feat: sustain pedal

This commit is contained in:
dogeystamp 2024-04-21 21:21:58 -04:00
parent 4fcc682406
commit ea70d75837
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38
4 changed files with 24 additions and 7 deletions

View File

@ -48,7 +48,8 @@ You should be able to play now.
- Ribbon cable sockets. The following is for my own piano, yours might be different:
- 18-pin 1.25mm pitch FFC connector
- 22-pin 1.25mm pitch FFC connector
- Many jumper cables
- Many jumper cables (40 male-to-female, ? male-to-male)
- Two alligator clips
- Breadboard
For the ribbon cable sockets, open up your piano and find the ribbon cables.
@ -60,7 +61,7 @@ Usually, these measurements can be found on the datasheets for FFC sockets.
## wiring
**Ensure all wires are well plugged in every time you use this circuit.**
**Ensure all wires, especially GND and power wires, are well plugged in every time you use this circuit.**
### rails
@ -119,3 +120,12 @@ Each scan should return exactly two connections, these being the forward and rev
If there are more connections, that means there is crosstalk.
Once the wiring is done, plug the ribbon cables from your piano into the sockets.
## sustain pedal
Using jumper wires and alligator clips, wire the Tip of the pedal's TRS jack into the GND rail.
Then, wire the Ring (middle metal part, surrounded by two black bands), into the pedal pin (by default GP8).
To attach the alligator clips to the [TRS jack](https://en.m.wikipedia.org/wiki/Phone_connector_(audio)#Design), you can strip the outer layer of a paperclip and wrap the metallic part around the jack.
Because the sustain pedal is normally-closed, failure to wire this appropriately could result in the sustain pedal being constantly on.
To disable the sustain pedal, comment out the `pedal_task` in `src/bin/piano_firmware.rs`.

View File

@ -489,6 +489,7 @@ async fn main(_spawner: Spawner) {
.spawn(matrix::pedal(
midi::Controller::SustainPedal,
p.PIN_8.into(),
false,
))
.unwrap();
}

View File

@ -3,20 +3,26 @@
use crate::midi;
use crate::pins;
use crate::unwrap;
use core::cmp::{min};
use core::cmp::min;
use embassy_rp::gpio;
use embassy_time::{Duration, Instant, Ticker};
/// Task to handle pedals in MIDI
///
/// `norm_open` represents a normally open switch
#[embassy_executor::task]
pub async fn pedal(pedal: midi::Controller, pin: gpio::AnyPin) {
pub async fn pedal(pedal: midi::Controller, pin: gpio::AnyPin, norm_open: bool) {
let mut inp = gpio::Input::new(pin, gpio::Pull::Up);
let chan = midi::MidiChannel::new(0);
loop {
let on_val = if norm_open { 64 } else { 0 };
let off_val = if norm_open { 0 } else { 64 };
inp.wait_for_low().await;
chan.controller(pedal, 64).await;
chan.controller(pedal, on_val).await;
log::debug!("{pedal:?} set to {on_val}");
inp.wait_for_high().await;
chan.controller(pedal, 0).await;
chan.controller(pedal, off_val).await;
log::debug!("{pedal:?} set to {off_val}");
}
}

View File

@ -42,7 +42,7 @@ impl NoteMsg {
}
}
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
pub enum Controller {
SustainPedal = 64,
}