Stap 14: De zender Program
De zender is een beetje lastiger als u een setup SquidBee gebruikt omdat het ontbreekt een ATMEGA-chip.
Eerst Haal het XBee schild.
Indien nodig, toevoegen en bootload en de chip.
Dan, net als de andere bestuur, de jumper van de macht-selectie omzetten in USB, en vervolgens uploaden met de volgende code:
/* Flamethrowing Jack-O'-Lantern Trigger code Based on Button example code http://www.arduino.cc/en/Tutorial/Button created 2005 by DojoDave <http://www.0j0.org> modified 28 Oct 2010 by Tom Igoe The circuit: * pushbutton attached to pin 2 from +5V * 10K resistor attached to pin 2 from ground This code is in the public domain. */ // constants won't change. They're used here to // set pin numbers: const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin // variables will change: int buttonState = 0; // variable for reading the pushbutton status void setup() { // initialize serial communication: Serial.begin(9600); // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); } void loop(){ // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH); //transmit a High command to the pumpkin and delay a second so that it does not recieve more than one command //per button press Serial.println('h'); delay(1000); } else { // turn LED off: digitalWrite(ledPin, LOW); } }
Wanneer u klaar bent, haal de USB en sluit het XBee schild. U moet ook moeras terug de jumpers van de macht op de Arduino.
Tot slot, omzetten in beide de TX/RX jumpers op het schild XBee vanaf USB XBee.