#define PICK 0 // The pin on which the pick is connected #define SWITCH 9 // The pin on which the serial/switch switch // is connected #define SERIAL_MODE 0 // Indicate The MIDI Pick is in serial mode #define SWITCH_MODE 1 // Indicate The MIDI Pick is in switch mode #define THRESHOLD 100 // The threshold that must be passed to // switch from sending a 1 to sending a 0, // and vice versa, when the physical switch // is in "switch" mode. void run( void ) { loop_start: static int scaled_pick_value = 0; // The MIDI Pick's pressure val static int physical_switch = 0; // State of the onboard switch static int all_leds = 127; // full pressure (CHANGE) static int half_leds = 64; // half pressure (CHANGE) static int previous_value = 0; static int send = 0; physical_switch = digitalRead( SWITCH ); ( physical_switch == SERIAL_MODE ) ? turn_on_serial_led() : turn_on_switch_led(); // 1. Read the pin on which The MIDI Pick's force-sensing resistor // transmits data. // 2. Divide that number by 8, which scales the highest value // down to 128. // 3. Assign that value to the int variable scaled_pick_value, then // check it against the previous_value. // // If the current value of the pick is the same as the previous, // branch to the beginning of this loop for a new datum. if((scaled_pick_value = (analogRead( PICK ) / 8)) == previous_value) goto loop_start; // If the physical switch is in serial mode, turn on the pressure // leds. (How many of those leds will light up depends on how // hard the pick is being pressed.) Then, send data long the // bluetooth connection. if( physical_switch == SERIAL_MODE ) { gauge_pressure( &scaled_pick_value ); send_data( &scaled_pick_value ); } else // The physical switch is in switch (not serial) mode, which means // that I must test for finger pressure exceeding a certain // THRESHOLD. If the scaled_pick_value execeeds the THRESHOLD, // then I need to switch from sending a 1 to sending a 0, or // vice versa. { if( scaled_pick_value > THRESHOLD ) // I'm sending either a 0 or a 1. If I'm currently sending // a 0, then assign 1 to variable send, turn on 3 of the // 5 LEDs, send a 1 along the bluetooth connection, wait // for 250 milliseconds (1/4 of a second), and proceed. if( send == 0 ) { send = 1; gauge_pressure( &all_leds ); send_one(); delay( 250 ); } else { send = 0; gauge_pressure( &half_leds ); send_zero(); delay( 250 ); } } }