I am working with an Attiny85 and an HC-05 bluetooth module trying to turn LEDs on and off using a cell phone. The cell phone is sending number (0-9) and I am trying to get the attiny to respond accordingly. I am using the code below and it is not working. One thing I found was that if I changed the received signal from 1 to -1 it would work, but this did not work with all the numbers, it was also reading the 10 signal as -2. I was wondering if anyone has had something like this happen before where the attiny interprets the signal received as something different than what was sent. I tried changing the baud rate but this did not help either. Please let me know if any additional information is needed.
Thank you,
#include <SoftwareSerial.h> //Software Serial Port
#define Rx 3
#define Tx 4
SoftwareSerial blueToothSerial(Rx, Tx);
int ledPin1 = 0; // the pin that the LED is attached to
int ledPin2 = 1;
int ledPin3 = 2;
//byte serialA;
void setup()
{
pinMode(Rx, INPUT);
pinMode(Tx, OUTPUT);
// initialize the serial communication:
// initialize the ledPin as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
blueToothSerial.begin(9600);
}
void loop() {
digitalWrite(ledPin1, HIGH);
char recvChar;
while(1){
//check if there's any data sent from the remote bluetooth shield
if(blueToothSerial.available()){
recvChar = blueToothSerial.read();
if(recvChar == 0)
digitalWrite(ledPin1, LOW);
if(recvChar == 1)
digitalWrite(ledPin2, LOW);
if(recvChar == 2)
digitalWrite(ledPin3, LOW);
if(recvChar == 3)
digitalWrite(ledPin1, HIGH);
if(recvChar == 4)
digitalWrite(ledPin1, 60);
if(recvChar == 5)
digitalWrite(ledPin1, 15);
if(recvChar == 6)
digitalWrite(ledPin2, HIGH);
if(recvChar == 7)
digitalWrite(ledPin2, 60);
if(recvChar == 8)
digitalWrite(ledPin2, 15);
if(recvChar == 9)
digitalWrite(ledPin3, HIGH);
else
digitalWrite(ledPin1,LOW);
}
}
}