Created
April 12, 2011 03:42
-
-
Save kitschpatrol/914873 to your computer and use it in GitHub Desktop.
arduino serial communication code for the vhs cannon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (Serial.available() >= 3) { | |
// read and send stuff | |
// Incoming Packet Has form: | |
// Byte 1: Mic Display Level (0 - 10) | |
// Byte 2: VHS Display Level (0 - 10) | |
// Byte 3: Mix Display Level (0 - 10) | |
setMicLevelBar(Serial.read()); | |
setVHSLevelBar(Serial.read()); | |
setMixLevelBar(Serial.read()); | |
// Outgoing Packet has form: | |
// Mic level, VHS level, mix level | |
// Byte 1: Mic Level (0 - 255) | |
// Byte 2: VHS Level (0 - 255) | |
// Byte 3: Mix Level (0 - 255) | |
// Byte 4: Pot 1 (0 - 255) | |
// Byte 5: Pot 2 (0 - 255) | |
// Byte 6: Rotary Selector (0 - 11) | |
// Byte 7: Buttons | |
// Bit 1: Button A | |
// Bit 2: Button B | |
// Bit 3: Button C | |
// Bit 4: Button D | |
// Bit 5: Toggle 1 | |
// Bit 6: Toggle 2 | |
// Bit 7: Unused | |
// Bit 8: Unused | |
// Update debouncers | |
buttonA.update(); | |
buttonB.update(); | |
buttonC.update(); | |
buttonD.update(); | |
toggle1.update(); | |
toggle2.update(); | |
// pack the buttons byte | |
byte buttons = 0; | |
if(buttonA.read()) bitSet(buttons, 7); | |
if(buttonB.read()) bitSet(buttons, 6); | |
if(buttonC.read()) bitSet(buttons, 5); | |
if(buttonD.read()) bitSet(buttons, 4); | |
if(toggle1.read()) bitSet(buttons, 3); | |
if(toggle2.read()) bitSet(buttons, 2); | |
// Send to OF | |
Serial.print((byte)(255 - (analogRead(MIC_LEVEL_SLIDER_PIN) / 4))); | |
Serial.print((byte)(255 - (analogRead(VHS_LEVEL_SLIDER) / 4))); | |
Serial.print((byte)(255 - (analogRead(MIX_LEVEL_SLIDER_PIN) / 4))); | |
Serial.print((byte)(analogRead(POT_1_PIN) / 4)); | |
Serial.print((byte)(analogRead(POT_2_PIN) / 4)); | |
Serial.print(encoderValue); | |
Serial.print(buttons); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment