123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
-
- ///-------------------------------------------------------------------------------------------------
- ///
- /// \file TactiloControllerPanda.ino
- /// \brief Controlls the Tactilos on the Leonardos GPIOs, based on the messages from OpenVibes TactiloController Box Algorithm
- /// \author Tobias Baumann (TH-Nürnberg).
- /// \version 1.0.
- /// \date Mon Mar 7 14:02:56 2022.
- ///
- ///-------------------------------------------------------------------------------------------------
-
- //define used GPIO pins
- #define TAC1 7
- #define TAC2 8
- #define TAC3 9
- #define TAC4 10
- #define TAC5 11
- #define TAC6 12
-
- #define LED 13
-
-
- void setup()
- {
- //init serial
- Serial.begin(115200);
-
- //init GPIOs
- Serial.println("...init GPIOs");
- set_PinMode();
- set_AllLow();
- }
-
- void loop()
- {
- char SerialData;
-
- if(Serial.available() > 0)
- {
- SerialData = Serial.read();
- Serial.print("...Received Data: ");
- Serial.println(SerialData, DEC);
- }
-
- processSerialData(SerialData);
- }
-
- void set_PinMode()
- {
- //set all pins to OUTPUT
- pinMode(TAC1, OUTPUT);
- pinMode(TAC2, OUTPUT);
- pinMode(TAC3, OUTPUT);
- pinMode(TAC4, OUTPUT);
- pinMode(TAC5, OUTPUT);
- pinMode(TAC6, OUTPUT);
-
- pinMode(LED, OUTPUT);
- }
-
- void set_AllLow()
- {
- //set all pins to LOW
- digitalWrite(TAC1, LOW);
- digitalWrite(TAC2, LOW);
- digitalWrite(TAC3, LOW);
- digitalWrite(TAC4, LOW);
- digitalWrite(TAC5, LOW);
- digitalWrite(TAC6, LOW);
-
- digitalWrite(LED, LOW);
- }
-
- void processSerialData(char SerialData)
- {
- switch(SerialData)
- {
- case '0':
- if(digitalRead(LED) == LOW)
- {
- digitalWrite(LED, HIGH);
- Serial.println("...Start Tactile Session");
- }
- else
- {
- set_AllLow();
- Serial.println("...End Tactile Session");
- }
- break;
- case '1':
- digitalWrite(TAC1, !digitalRead(TAC1));
- Serial.println("Tactilo 1");
- break;
- case '2':
- digitalWrite(TAC2, !digitalRead(TAC2));
- Serial.println("Tactilo 2");
- break;
- case '3':
- digitalWrite(TAC3, !digitalRead(TAC3));
- Serial.println("Tactilo 3");
- break;
- case '4':
- digitalWrite(TAC4, !digitalRead(TAC4));
- Serial.println("Tactilo 4");
- break;
- case '5':
- digitalWrite(TAC5, !digitalRead(TAC5));
- Serial.println("Tactilo 5");
- break;
- case '6':
- digitalWrite(TAC6, !digitalRead(TAC6));
- Serial.println("Tactilo 6");
- break;
- default:
- break;
- }
- }
|