Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define LED_PIN 11
- #define BAUD 9600
- HardwareSerial Uart = HardwareSerial();
- void setup()
- {
- pinMode(LED_PIN, OUTPUT);
- digitalWrite(LED_PIN, HIGH);
- delay(1000);
- pinMode(LED_PIN, LOW);
- Serial.begin(BAUD); // USB, communication to PC or Mac
- Serial.println("SETUP teensy");
- Uart.begin(BAUD); // UART, communication to Dorkboard
- }
- char beacon[]="abcdef";
- char answer[]="fedcba";
- unsigned i = 0;
- long led_on_time=0;
- char input[]="000000";
- void loop()
- {
- unsigned char c;
- if (Uart.available()) {
- digitalWrite(LED_PIN, HIGH);
- led_on_time = millis()+200;
- c = Uart.read();
- if (c == beacon[0]){
- input[0] = c;
- i=1;
- }else if(i > 0){
- input[i] = c;
- i++;
- }
- if ( i >= strlen(beacon)){
- if (strcmp(input, beacon) == 0){
- digitalWrite(LED_PIN, HIGH);
- led_on_time = millis()+500;
- Uart.write(answer);
- Serial.println("Got beacon!");
- }else{
- strcpy("000000",input);
- }
- i=0;
- }
- }
- if (millis() > led_on_time) {
- digitalWrite(LED_PIN, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement