Commit c95d51a8 authored by robert.sharp's avatar robert.sharp

Update Main.ino to use the new Grove library.

parent 2016ee2c
......@@ -32,7 +32,7 @@
#include <lmic.h> //IBM LMIC Library
#include <hal/hal.h>
#include <SPI.h>
#include"AirQuality.h"
#include "Air_Quality_Sensor.h"
#include"Arduino.h"
// This EUI must be in little-endian format, so least-significant-byte
......@@ -54,7 +54,7 @@ static const u1_t PROGMEM APPKEY[16] = { 0xEE, 0xB3, 0xA4, 0x83, 0xBF, 0xEC, 0x0
void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);}
static int mydata = -1;
AirQuality airqualitysensor;
AirQualitySensor sensor(A0);
static osjob_t sendjob;
......@@ -142,7 +142,11 @@ void onEvent (ev_t ev) {
void do_send(osjob_t* j){
//Update mydata to be the current value of the sensor
mydata=airqualitysensor.slope();
mydata = sensor.getValue();
//test the sensor is working
Serial.print("Sensor value: ");
Serial.println(sensor.getValue());
// Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {
......@@ -157,9 +161,17 @@ void do_send(osjob_t* j){
void setup() {
Serial.begin(115200);
airqualitysensor.init(A0);
Serial.println(F("Starting"));
Serial.println("Waiting sensor to init...");
delay(20000);
if (sensor.init()) {
Serial.println("Sensor ready.");
} else {
Serial.println("Sensor ERROR!");
}
#ifdef VCC_ENABLE
// For Pinoccio Scout boards
pinMode(VCC_ENABLE, OUTPUT);
......@@ -178,17 +190,4 @@ void setup() {
void loop() {
os_runloop_once();
}
ISR(TIMER2_OVF_vect){
if(airqualitysensor.counter==122){//set 2 seconds as a detected duty{
airqualitysensor.last_vol=airqualitysensor.first_vol;
airqualitysensor.first_vol=analogRead(A0);
airqualitysensor.counter=0;
airqualitysensor.timer_index=1;
PORTB=PORTB^0x20;
}else{
airqualitysensor.counter++;
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment