opportunistic-xbee/well/main/main.ino

46 lines
742 B
Arduino
Raw Normal View History

2018-12-01 17:26:27 +00:00
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#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
LiquidCrystal_I2C screen(0x27, 16, 2);
XBeeWrapper xbee = XBeeWrapper();
2018-12-01 17:26:27 +00:00
// ACTUAL DATA
uint8_t wave_id = 250;
Packet send;
2018-12-01 17:26:27 +00:00
void setup() {
Serial.begin(38400);
Serial.println("+ ready");
2018-12-01 17:26:27 +00:00
screen.begin();
screen.backlight();
2018-12-01 17:26:27 +00:00
xbee.begin(38400);
2018-12-01 17:26:27 +00:00
}
void loop() {
delay(WAVE_TIMEOUT);
2018-12-01 17:26:27 +00:00
screen.clear();
screen.print("+ wave");
screen.print(wave_id+1);
2018-12-01 17:26:27 +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
if( xbee.broadcast(send) == XBWSEND_OK )
Serial.println("sent");
else
Serial.println("failed");
2018-12-01 17:26:27 +00:00
}