Advertisement
DanClarksonSound

Untitled

Apr 6th, 2020
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.09 KB | None | 0 0
  1. #include <Adafruit_SSD1306.h>
  2. #include <splash.h>
  3. #include <gfxfont.h>
  4. #include <Adafruit_GFX.h>
  5. #include <Adafruit_SPITFT.h>
  6. #include <Adafruit_SPITFT_Macros.h>
  7. #include <OSCMessage.h>
  8. #include <Ethernet2.h>
  9. #include <EthernetUdp2.h>
  10. #include <SPI.h>
  11. #include <OSCMessage.h>
  12.  
  13. #define SCREEN_WIDTH 128
  14. #define SCREEN_HEIGHT 64
  15.  
  16. EthernetUDP Udp;
  17.  
  18. const int button1Pin = 2;
  19. const int button2Pin = 3;
  20. const int button3Pin = 5;
  21. const int button4Pin = 6;
  22.  
  23. const int led1Pin = 7;
  24. const int led2Pin = 8;
  25. const int led3Pin = 9;
  26. const int led4Pin = 10;
  27.  
  28. int button1State;
  29. int button2State;
  30. int button3State;
  31. int button4State;
  32.  
  33. int lastButton1State = LOW;
  34. int lastButton2State = LOW;
  35. int lastButton3State = LOW;
  36. int lastButton4State = LOW;
  37.  
  38. int playHeadNum = 0;
  39.  
  40. unsigned long lastDebounce1Time = 0;
  41. unsigned long lastDebounce2Time = 0;
  42. unsigned long lastDebounce3Time = 0;
  43. unsigned long lastDebounce4Time = 0;
  44.  
  45. unsigned long debounce1Delay = 50;
  46. unsigned long debounce2Delay = 50;
  47. unsigned long debounce3Delay = 50;
  48. unsigned long debounce4Delay = 50;
  49.  
  50. //the Arduino's IP
  51. IPAddress ip(10, 101, 2, 100);
  52. //destination IP
  53. IPAddress outIp(10, 101, 2, 1);
  54.  
  55. const unsigned int outPort = 53000;
  56.  
  57. Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
  58.  
  59. byte mac[] = {0x90, 0xA2, 0xDA, 0x11, 0x35, 0x2A};
  60.  
  61. void setup() {
  62.  
  63.   Ethernet.begin(mac, ip);
  64.   Udp.begin(9001);
  65.  
  66.   if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {                // Address 0x3C for 128x64
  67.     Serial.println(F("SSD1306 allocation failed"));
  68.     loop(); {
  69.     }
  70.     for(;;);
  71.   }
  72.  
  73.   Serial.begin (9600);
  74.  
  75.   pinMode(button1Pin, INPUT_PULLUP);
  76.   pinMode(button2Pin, INPUT_PULLUP);
  77.   pinMode(button3Pin, INPUT_PULLUP);
  78.   pinMode(button4Pin, INPUT_PULLUP);
  79.  
  80.   pinMode(led1Pin, OUTPUT);
  81.   pinMode(led2Pin, OUTPUT);
  82.   pinMode(led3Pin, OUTPUT);
  83.   pinMode(led4Pin, OUTPUT);
  84.  
  85.   digitalWrite(led1Pin, HIGH);
  86.   digitalWrite(led2Pin, HIGH);
  87.   digitalWrite(led3Pin, HIGH);
  88.   digitalWrite(led4Pin, HIGH);
  89.  
  90.   delay(1000);
  91.   display.clearDisplay();
  92.   display.setTextSize(5);                          
  93.   display.setTextColor(WHITE);
  94.   display.setCursor(0, 0);
  95.   display.display();
  96.   delay(100);
  97.  
  98. Serial.println("System Ready");
  99. }
  100.  
  101. void loop() {
  102.  
  103. int reading1 = digitalRead(button1Pin);
  104. int reading2 = digitalRead(button2Pin);
  105. int reading3 = digitalRead(button3Pin);
  106. int reading4 = digitalRead(button4Pin);
  107.  
  108. // BUTTON 1 - GO
  109.  
  110.   if (reading1 != lastButton1State) {
  111.  
  112.     lastDebounce1Time = millis();
  113.   }
  114.  
  115.   if ((millis() - lastDebounce1Time) > debounce1Delay) {
  116.  
  117.     if (reading1 != button1State) {
  118.       button1State = reading1;
  119.       if (button1State == LOW) {
  120.        
  121.         OSCMessage msg("/");
  122.         msg.add("go");
  123.  
  124.         Udp.beginPacket(outIp, outPort);
  125.         msg.send(Udp);
  126.         Udp.endPacket();
  127.         msg.empty();
  128.  
  129.         Serial.println("Go Pressed");
  130.  
  131.         digitalWrite(led1Pin, LOW);
  132.         delay(100);
  133.         digitalWrite(led1Pin, HIGH);
  134.  
  135.         display.clearDisplay();
  136.         display.setCursor(0,20);
  137.         display.print(playHeadNum);
  138.         display.display();
  139.        
  140.       }
  141.     }
  142.   }
  143.   lastButton1State = reading1;
  144.  
  145. // BUTTON 2 - PANIC
  146.  
  147.   if (reading2 != lastButton2State) {
  148.  
  149.     lastDebounce2Time = millis();
  150.   }
  151.  
  152.   if ((millis() - lastDebounce2Time) > debounce2Delay) {
  153.  
  154.     if (reading2 != button2State) {
  155.       button2State = reading2;
  156.       if (button2State == LOW) {
  157.        
  158.         OSCMessage msg("/");
  159.         msg.add("panic");
  160.  
  161.         Udp.beginPacket(outIp, outPort);
  162.         msg.send(Udp);
  163.         Udp.endPacket();
  164.         msg.empty();
  165.  
  166.         Serial.println("Panic Pressed");
  167.  
  168.         digitalWrite(led2Pin, LOW);
  169.         delay(100);
  170.         digitalWrite(led2Pin, HIGH);
  171.       }
  172.     }
  173.   }
  174.   lastButton2State = reading2;
  175.  
  176.   // BUTTON 3 - PANIC
  177.  
  178.   if (reading3 != lastButton3State) {
  179.  
  180.     lastDebounce3Time = millis();
  181.   }
  182.  
  183.   if ((millis() - lastDebounce3Time) > debounce3Delay) {
  184.  
  185.     if (reading3 != button3State) {
  186.       button3State = reading3;
  187.       if (button3State == LOW) {
  188.        
  189.         OSCMessage msg("/");
  190.         msg.add("next");
  191.  
  192.         Udp.beginPacket(outIp, outPort);
  193.         msg.send(Udp);
  194.         Udp.endPacket();
  195.         msg.empty();
  196.  
  197.         Serial.println("Next Pressed");
  198.  
  199.         digitalWrite(led3Pin, LOW);
  200.         delay(100);
  201.         digitalWrite(led3Pin, HIGH);
  202.       }
  203.     }
  204.   }
  205.   lastButton3State = reading3;
  206.  
  207. // BUTTON 4 - PREVIOUS
  208.  
  209.   if (reading4 != lastButton4State) {
  210.  
  211.     lastDebounce4Time = millis();
  212.   }
  213.  
  214.   if ((millis() - lastDebounce4Time) > debounce4Delay) {
  215.  
  216.     if (reading4 != button4State) {
  217.       button4State = reading4;
  218.       if (button4State == LOW) {
  219.        
  220.         OSCMessage msg("/");
  221.         msg.add("previous");
  222.  
  223.         Udp.beginPacket(outIp, outPort);
  224.         msg.send(Udp);
  225.         Udp.endPacket();
  226.         msg.empty();
  227.  
  228.         Serial.println("Previous Pressed");
  229.  
  230.         digitalWrite(led4Pin, LOW);
  231.         delay(100);
  232.         digitalWrite(led4Pin, HIGH);
  233.       }
  234.     }
  235.   }
  236.   lastButton4State = reading4;
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement