I have a short program which should receive data, use this data to turn on/off an LED, and send data when a button is pressed. It is deployed on a Digispark board. The button is connected to INT0
port (PB2). The interrupt works, but data is not send. Receiving data works fine.
What am I missing here?
#include <SoftSerial.h>
#define RxD 1
#define TxD 0
#define out 3
#define btn 2
#define testled 4
SoftSerial blueToothSerial(RxD, TxD); //RX, TX
volatile int buttonState = 0;
void setup() {
pinMode(out, OUTPUT);
pinMode(btn, INPUT);
pinMode(testled, OUTPUT);
setupBlueToothConnection();
digitalWrite(out, HIGH);
digitalWrite(testled, HIGH);
attachInterrupt(0, intrpt, CHANGE);
}
void loop() {
char newVal;
if(blueToothSerial.available()){
newVal = blueToothSerial.read();
if (newVal == '1') {
digitalWrite(out, HIGH);
} else {
digitalWrite(out, LOW);
}
}
}
void intrpt() {
buttonState = digitalRead(btn);
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(testled, HIGH);
} else {
// turn LED off:
digitalWrite(testled, LOW);
blueToothSerial.println("0");
}
}
void setupBlueToothConnection() {
blueToothSerial.begin(9600);
blueToothSerial.print("\r\n+STWMOD=0\r\n");
blueToothSerial.print("\r\n+STNA=HC-05\r\n");
blueToothSerial.print("\r\n+STOAUT=1\r\n");
blueToothSerial.print("\r\n+STAUTO=0\r\n");
delay(2000);
blueToothSerial.print("bluetooth connected!\n");
delay(2000);
blueToothSerial.flush();
}
EDIT
Serial data is sent fine. The above code works. On Windows I can see the data are coming, but not on OS X.