Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_SSD1306.h>
- #include <splash.h>
- #include <gfxfont.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SPITFT.h>
- #include <Adafruit_SPITFT_Macros.h>
- #include <OSCMessage.h>
- #include <Ethernet2.h>
- #include <EthernetUdp2.h>
- #include <SPI.h>
- #include <OSCMessage.h>
- #define SCREEN_WIDTH 128
- #define SCREEN_HEIGHT 64
- EthernetUDP Udp;
- const int button1Pin = 2;
- const int button2Pin = 3;
- const int button3Pin = 5;
- const int button4Pin = 6;
- const int led1Pin = 7;
- const int led2Pin = 8;
- const int led3Pin = 9;
- const int led4Pin = 10;
- int button1State;
- int button2State;
- int button3State;
- int button4State;
- int lastButton1State = LOW;
- int lastButton2State = LOW;
- int lastButton3State = LOW;
- int lastButton4State = LOW;
- int playHeadNum = 0;
- unsigned long lastDebounce1Time = 0;
- unsigned long lastDebounce2Time = 0;
- unsigned long lastDebounce3Time = 0;
- unsigned long lastDebounce4Time = 0;
- unsigned long debounce1Delay = 50;
- unsigned long debounce2Delay = 50;
- unsigned long debounce3Delay = 50;
- unsigned long debounce4Delay = 50;
- //the Arduino's IP
- IPAddress ip(10, 101, 2, 100);
- //destination IP
- IPAddress outIp(10, 101, 2, 1);
- const unsigned int outPort = 53000;
- Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
- byte mac[] = {0x90, 0xA2, 0xDA, 0x11, 0x35, 0x2A};
- void setup() {
- Ethernet.begin(mac, ip);
- Udp.begin(9001);
- if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x64
- Serial.println(F("SSD1306 allocation failed"));
- loop(); {
- }
- for(;;);
- }
- Serial.begin (9600);
- pinMode(button1Pin, INPUT_PULLUP);
- pinMode(button2Pin, INPUT_PULLUP);
- pinMode(button3Pin, INPUT_PULLUP);
- pinMode(button4Pin, INPUT_PULLUP);
- pinMode(led1Pin, OUTPUT);
- pinMode(led2Pin, OUTPUT);
- pinMode(led3Pin, OUTPUT);
- pinMode(led4Pin, OUTPUT);
- digitalWrite(led1Pin, HIGH);
- digitalWrite(led2Pin, HIGH);
- digitalWrite(led3Pin, HIGH);
- digitalWrite(led4Pin, HIGH);
- delay(1000);
- display.clearDisplay();
- display.setTextSize(5);
- display.setTextColor(WHITE);
- display.setCursor(0, 0);
- display.display();
- delay(100);
- Serial.println("System Ready");
- }
- void loop() {
- int reading1 = digitalRead(button1Pin);
- int reading2 = digitalRead(button2Pin);
- int reading3 = digitalRead(button3Pin);
- int reading4 = digitalRead(button4Pin);
- // BUTTON 1 - GO
- if (reading1 != lastButton1State) {
- lastDebounce1Time = millis();
- }
- if ((millis() - lastDebounce1Time) > debounce1Delay) {
- if (reading1 != button1State) {
- button1State = reading1;
- if (button1State == LOW) {
- OSCMessage msg("/");
- msg.add("go");
- Udp.beginPacket(outIp, outPort);
- msg.send(Udp);
- Udp.endPacket();
- msg.empty();
- Serial.println("Go Pressed");
- digitalWrite(led1Pin, LOW);
- delay(100);
- digitalWrite(led1Pin, HIGH);
- display.clearDisplay();
- display.setCursor(0,20);
- display.print(playHeadNum);
- display.display();
- }
- }
- }
- lastButton1State = reading1;
- // BUTTON 2 - PANIC
- if (reading2 != lastButton2State) {
- lastDebounce2Time = millis();
- }
- if ((millis() - lastDebounce2Time) > debounce2Delay) {
- if (reading2 != button2State) {
- button2State = reading2;
- if (button2State == LOW) {
- OSCMessage msg("/");
- msg.add("panic");
- Udp.beginPacket(outIp, outPort);
- msg.send(Udp);
- Udp.endPacket();
- msg.empty();
- Serial.println("Panic Pressed");
- digitalWrite(led2Pin, LOW);
- delay(100);
- digitalWrite(led2Pin, HIGH);
- }
- }
- }
- lastButton2State = reading2;
- // BUTTON 3 - PANIC
- if (reading3 != lastButton3State) {
- lastDebounce3Time = millis();
- }
- if ((millis() - lastDebounce3Time) > debounce3Delay) {
- if (reading3 != button3State) {
- button3State = reading3;
- if (button3State == LOW) {
- OSCMessage msg("/");
- msg.add("next");
- Udp.beginPacket(outIp, outPort);
- msg.send(Udp);
- Udp.endPacket();
- msg.empty();
- Serial.println("Next Pressed");
- digitalWrite(led3Pin, LOW);
- delay(100);
- digitalWrite(led3Pin, HIGH);
- }
- }
- }
- lastButton3State = reading3;
- // BUTTON 4 - PREVIOUS
- if (reading4 != lastButton4State) {
- lastDebounce4Time = millis();
- }
- if ((millis() - lastDebounce4Time) > debounce4Delay) {
- if (reading4 != button4State) {
- button4State = reading4;
- if (button4State == LOW) {
- OSCMessage msg("/");
- msg.add("previous");
- Udp.beginPacket(outIp, outPort);
- msg.send(Udp);
- Udp.endPacket();
- msg.empty();
- Serial.println("Previous Pressed");
- digitalWrite(led4Pin, LOW);
- delay(100);
- digitalWrite(led4Pin, HIGH);
- }
- }
- }
- lastButton4State = reading4;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement