2018-12-01 17:26:27 +00:00
|
|
|
#include <Wire.h>
|
|
|
|
#include <LiquidCrystal_I2C.h>
|
2018-12-03 09:54:53 +00:00
|
|
|
#include "xbee_wrapper.h"
|
|
|
|
#include "packet.h"
|
2018-12-01 17:26:27 +00:00
|
|
|
|
2018-12-01 17:38:00 +00:00
|
|
|
#define WAVE_TIMEOUT 5000
|
2018-12-01 17:26:27 +00:00
|
|
|
|
|
|
|
// Peripherals
|
2018-12-03 14:29:56 +00:00
|
|
|
LiquidCrystal_I2C screen(0x20, 16, 2);
|
2018-12-03 09:54:53 +00:00
|
|
|
XBeeWrapper xbee = XBeeWrapper();
|
2018-12-01 17:26:27 +00:00
|
|
|
|
|
|
|
// ACTUAL DATA
|
|
|
|
uint8_t wave_id = 250;
|
2018-12-03 09:54:53 +00:00
|
|
|
Packet send;
|
2018-12-01 17:26:27 +00:00
|
|
|
|
|
|
|
void setup() {
|
2018-12-03 09:54:53 +00:00
|
|
|
Serial.begin(38400);
|
|
|
|
Serial.println("+ ready");
|
2018-12-01 17:26:27 +00:00
|
|
|
|
2018-12-03 09:54:53 +00:00
|
|
|
screen.begin();
|
|
|
|
screen.backlight();
|
2018-12-03 14:29:56 +00:00
|
|
|
screen.home();
|
|
|
|
screen.setCursor(0,0);
|
|
|
|
screen.print("ready");
|
2018-12-01 17:26:27 +00:00
|
|
|
|
2018-12-03 09:54:53 +00:00
|
|
|
xbee.begin(38400);
|
2018-12-01 17:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
|
2018-12-03 09:54:53 +00:00
|
|
|
delay(WAVE_TIMEOUT);
|
2018-12-01 17:26:27 +00:00
|
|
|
|
2018-12-03 09:54:53 +00:00
|
|
|
screen.clear();
|
|
|
|
screen.print("+ wave");
|
|
|
|
screen.print(wave_id+1);
|
2018-12-01 17:26:27 +00:00
|
|
|
|
2018-12-03 09:54:53 +00:00
|
|
|
// increment wave id (will overflow from 255 to 0)
|
|
|
|
send.setOpcode(0);
|
|
|
|
send.setWave(++wave_id);
|
|
|
|
send.setDist(0);
|
2018-12-03 10:24:32 +00:00
|
|
|
send.setSender(42);
|
2018-12-01 17:26:27 +00:00
|
|
|
|
2018-12-03 09:54:53 +00:00
|
|
|
if( xbee.broadcast(send) == XBWSEND_OK )
|
|
|
|
Serial.println("sent");
|
|
|
|
else
|
|
|
|
Serial.println("failed");
|
2018-12-01 17:26:27 +00:00
|
|
|
|
|
|
|
}
|