Hi,
I created software for object detection.
Now I would like to send the information by wifi on doc Excel but I have no idea how to develop it.
I would like to send the information only when there is a change in the state of the LED (Red or Green).
Could you help me ?
Thank you.
Here is my code :
enum {
WAIT_LESS_THAN_100 = 0,
WAIT_FOR_MORE_THAN_100,
CHECK_TIME_ELAPSED_SINCE_CHANGE,
};
const int analogInPin = 9;
const int pinSensorInput = 0;
int sensorValue;
int b;
#include <Adafruit_NeoPixel.h> // Charge la librairie Neo Pixel d'Adafruit utilisé pour piloter le ruban de LED
#define PIXEL_PIN 6 // On définit le pin où est connecté la patte DATA du bandeau
Adafruit_NeoPixel leds(5, 6, NEO_GRB + NEO_KHZ800); // initialation ruban
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
// initialize l'entrée capteur
pinMode(9, INPUT_PULLUP);
// initialize le bandeau LED
leds.begin(); // Lance la connection
leds.show(); // Initialise toute les led à 'off'
/* Définition des couleurs */
int GREEN[3] = { 0, 255, 0 }; // Couleur Verte
int RED[3] = { 255, 0, 0 }; // Couleur Rouge
int CYAN[3] = { 0, 255, 255 }; // Couleur Cyan
int YELLOW[3] = { 255, 125, 0 }; // Couleur Jaune
int ORANGE[3] = { 255, 40, 0 }; // Couleur Orange
int PURPLE[3] = { 255, 0, 255 }; // Couleur Violette
int PINK[3] = { 255, 0, 100 }; // Couleur Rose
int BLUE[3] = { 0, 0, 255 }; // Couleur Bleu
int WHITE[3] = { 255, 255, 255 }; // Couleur Blanche
// initialize la sortie led
Serial.begin(9600);
}
void loop() {
leds.setBrightness(60); // Règle la luminosité à 100 % de la luminosité maximale
static uint8_t
state = WAIT_LESS_THAN_100;
static uint32_t
timeStateChange,
timeReadSensor = 0;
uint32_t
timeNow = millis();
// si detection 15x/sec
if ((timeNow - timeReadSensor) >= 1000ul) {
timeReadSensor = timeNow;
sensorValue = analogRead(analogInPin);
Serial.println(sensorValue);
} //if
switch (state) {
case WAIT_LESS_THAN_100:
//we wait here for the sensor to read < 30
if (sensorValue < 30) {
//If my sensor is less than 30: it is the RED LED ON
leds.fill(leds.Color(255, 0, 0), 0, 5);
leds.show();
//then go to the state waiting for the sensor to read >= 100
state = WAIT_FOR_MORE_THAN_100;
} //if
break;
case WAIT_FOR_MORE_THAN_100:
//sensor is less than 30 now; here we wait for it to go >= 100
if (sensorValue >= 30) {
//If my sensor is greater than 30 for less than 10s since the change of state of my sensor: the RED LED lights up
//
//this is same LED state as <100
leds.fill(leds.Color(255, 0, 0), 0, 5);
leds.show();
//get the time we saw this transition to >= 100
timeStateChange = timeNow;
//and move to time the 10-sec period
state = CHECK_TIME_ELAPSED_SINCE_CHANGE;
} //if
break;
case CHECK_TIME_ELAPSED_SINCE_CHANGE:
//value had increased to >=100; if it falls below 100 again, go back to the first state
if (sensorValue < 30)
state = WAIT_LESS_THAN_100;
//otherwise check to see if 10-second has elapsed...
else if ((timeNow - timeStateChange) >= 15000ul) {
//If my sensor is greater than 30 for more than 5s since
//the change of state of my sensor: the GREEN LED lights up
leds.fill(leds.Color(0, 255, 0), 0, 5);
leds.show();
//I'm guessing you can go back to wait for <100 again
state = WAIT_LESS_THAN_100;
} //else
break;
} //switch
} //loop