Last active
March 7, 2018 06:54
-
-
Save cpbotha/81a083e4ab4cdc6b60ef543dedbee5fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// what we would like to see: first LED then second LED lights up on the WS2812 strip | |
// what we see instead: first LED (indicates startup), but then first 4 LEDs go on together, meaning xbee never talked back | |
// with SoftwareSerial(2,3) and the SparkFun shield switched to dline (vs UART), it does work. | |
#include <FastLED.h> | |
#include <XBee.h> | |
#include <Printers.h> | |
#define DATA_PIN 9 | |
#define NUM_LEDS 4 | |
CRGBArray<NUM_LEDS> leds; | |
// construct XBee object to be use as API to the xbee module | |
XBee xbee = XBee(); | |
// sets the command to get the MY address | |
uint8_t myCmd[] = {'M', 'Y'}; | |
// Sets the command to exit AT mode. | |
uint8_t cnCmd[] = {'C','N'}; | |
// Initialises the AT Request and Response. | |
AtCommandRequest atRequest = AtCommandRequest(); | |
AtCommandResponse atResponse = AtCommandResponse(); | |
void setup() { | |
// put your setup code here, to run once: | |
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); | |
Serial.begin(9600); | |
xbee.begin(Serial); | |
// startup delay for xbee to wake-up (I'm desperate) | |
delay(5000); | |
// show that we're doing something | |
leds[0] = CHSV(0.5, 255, 255); | |
FastLED.show(); | |
addressRead(); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
} | |
void addressRead() | |
{ | |
// Sets the AT Command to Serial Low Read. | |
atRequest.setCommand(myCmd); | |
// Sends the AT Command. | |
xbee.send(atRequest); | |
// Waits for a response and checks for the correct response code. | |
if (xbee.readPacket(5000)) | |
{ | |
if(xbee.getResponse().getApiId() == AT_COMMAND_RESPONSE) | |
{ | |
xbee.getResponse().getAtCommandResponse(atResponse); | |
if(atResponse.isOk()) | |
{ | |
// second LED means we could read MY from the xbee | |
leds[1] += CHSV(128, 255, 192); | |
} | |
} | |
} | |
else { | |
// ERROR: we keep on arriving here :( :( :( | |
leds(0,3) = CHSV(128, 255, 192); | |
} | |
// Sets the AT Command to the Close Command. | |
atRequest.setCommand(cnCmd); | |
xbee.send(atRequest); | |
FastLED.show(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment