Johanneszockt1

Untitled

Mar 29th, 2021
691
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define BAUD 115200
  2. String StringArray[] = {"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"};
  3. void setup() {
  4.   // put your setup code here, to run once:
  5.   Serial.begin(BAUD);
  6.   //send a character A to tell processing we are ready
  7.   Serial.println("A");
  8. }
  9.  
  10. void loop() {
  11.   // put your main code here, to run repeatedly:
  12. }
  13.  
  14. //this function reads 3 integer values direcly behind each other, and expects a start character in front of it
  15. //input should be A123,234,456\r\n
  16. void serialEvent() {
  17.   while (Serial.available() > 0) {
  18.     char startChar = Serial.read();
  19.     if (startChar == 'A') {
  20.       //when the start char has been received and read read the 3 integers:
  21.       int val = Serial.parseInt();
  22.       Serial.println(val);
  23.       Serial.println(StringArray[val]);
  24.     }
  25.   }
  26. }
RAW Paste Data