Hi Guys
I am designing a remote control system and need a little help with incorporating ZigBee for the wireless communication between both Arduino Leonardo’s. One is the remote control and the other is the receiver. Can someone please help me to include the ZigBee code into the code i already have.
Thanks
Below is the code i am currently using
#include <SoftwareSerial.h>
const int buttonPin1 = 7;
const int buttonPin2 = 6;
const int buttonPin3 = 5;
const int buttonPin4 = 4;
const int buttonPin5 = 8;
const int buttonPin6 = 9;
const int ledPin = 13;
SoftwareSerial zigBee(3,2);
int buttonState = 0;
void setup() {
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
pinMode(buttonPin4, INPUT_PULLUP);
pinMode(buttonPin5, INPUT_PULLUP);
pinMode(buttonPin6, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
digitalWrite (ledPin, HIGH);
Serial.begin(9600);
zigBee.begin(9600); //begin software serial between XBee and Arduino Leonardo
Keyboard.begin();
}
void loop() {
if (digitalRead(buttonPin1) == LOW) {
// turn LED on:
digitalWrite(ledPin, !digitalRead(ledPin));
}
if (digitalRead(buttonPin2) == LOW) {
// turn LED on:
digitalWrite(ledPin, !digitalRead(ledPin));
}
if (digitalRead(buttonPin3) == LOW) {
// turn LED on:
digitalWrite(ledPin, !digitalRead(ledPin));
}
if (digitalRead(buttonPin4) == LOW) {
// turn LED on:
digitalWrite(ledPin, !digitalRead(ledPin));
}
if (digitalRead(buttonPin5) == LOW) {
// turn LED on:
digitalWrite(ledPin, !digitalRead(ledPin));
}
if (digitalRead(buttonPin6) == LOW) {
// turn LED on:
digitalWrite(ledPin, !digitalRead(ledPin));
}
if (!digitalRead(buttonPin1)) // if first button is pressed, 32 is “space bar” in ascii table and will play the media
Keyboard.write(32);
if (!digitalRead(buttonPin2)) // if second button is pressed, 115 is the letter “s” in ascii table and will stop the media
Keyboard.write(115);
if (!digitalRead(buttonPin3)) // if third button is pressed, 110 is the letter “n” in the ascii table and will play next song/video
Keyboard.write(110);
if (!digitalRead(buttonPin4)) // if fourth button is pressed, 112 is the letter “p” in the ascii table and will play the previous song/video
Keyboard.write(112);
if (!digitalRead(buttonPin5)) // if fifth button is pressed, 62 is the “>” button in the ascii table and will increase volume
Keyboard.write(62);
if (!digitalRead(buttonPin6)) // if sixth button is pressed, 60 is the “<” button in the ascii table and will decreases volume
Keyboard.write(60);
}