HELP !! sketch a debugger....
Publié : 16 nov. 2016, 21:52
Bonjour
j essaye de combiner plusieurs sketchs sur un seul arduino nano
celui d un capteur de temperature ;
https://github.com/mysensors/MySensorsA ... tureSensor
et de 3 boutons standard ;
https://github.com/mysensors/MySensorsA ... itchSensor
un seul des 3 boutons marche, pas les deux autres, et la sonde de temperature envoye bien des valeurs mais un peux trop souvant j aimerais qu elle les envoye que toutes les 1 secondes .....
/**
* REVISION HISTORY
* Version 1.0 - MrLynx
*
* DESCRIPTION
* MAX6875 High temperature sensor with range: -200 degC - +1300 degC
* http://forum.mysensors.org/topic/641/max6675
*
* Connect MAX6675 - Arduino
* CS0 - 4
* SO - 3
* SCLK - 5
* VCC - 5V
* GND - GND
*
*
* button - 6
*
*/
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <SPI.h>
#include <MySensors.h>
#include <MAX6675.h>
#include <Bounce2.h>
uint8_t CS0 = 4; // CS pin on MAX6675
uint8_t SO = 3; // SO pin of MAX6675
uint8_t SCLK = 5; // SCK pin of MAX6675
uint8_t units = 1; // Units to readout temp (0 = °F, 1 = °C)
float temperature = 0.0; // Temperature output variable
float lastTemperature;
unsigned long SLEEP_TIME = 5000;
bool metric = true;
MyMessage msg(0, V_TEMP);
// Initialize the MAX6675 Library for our chip
MAX6675 temp0(CS0, SO, SCLK, units);
#define CHILD_ID 3
#define CHILDb_ID 3
#define CHILDc_ID 3
#define BUTTON_PIN 6
#define BUTTONb_PIN 6
#define BUTTONc_PIN 6
Bounce debouncer = Bounce();
int oldValue=-1;
// Change to V_LIGHT if you use S_LIGHT in presentation below
MyMessage msgbutton(CHILD_ID,V_TRIPPED);
MyMessage msgbuttonb(CHILDb_ID,V_TRIPPED);
MyMessage msgbuttonc(CHILDc_ID,V_TRIPPED);
void setup()
{
// Setup the button
pinMode(BUTTON_PIN,INPUT);
pinMode(BUTTONb_PIN,INPUT);
pinMode(BUTTONc_PIN,INPUT);
// Activate internal pull-up
digitalWrite(BUTTON_PIN,HIGH);
digitalWrite(BUTTONb_PIN,HIGH);
digitalWrite(BUTTONc_PIN,HIGH);
// After setting up the button, setup debouncer
debouncer.attach(BUTTON_PIN);
debouncer.attach(BUTTONb_PIN);
debouncer.attach(BUTTONc_PIN);
debouncer.interval(5);
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Max6675 Temp Sensor", "1.0");
// Present all sensors to controller
present(0, S_TEMP);
// Register binary input sensor to gw (they will be created as child devices)
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
present(CHILD_ID, S_DOOR);
}
void loop()
{
debouncer.update();
// Get the update value
int value = debouncer.read();
if (value != oldValue)
{// Send in the new value
send(msgbutton.set(value==HIGH ? 1 : 0));
oldValue = value; }
if (value != oldValue)
{// Send in the new value
send(msgbuttonb.set(value==HIGH ? 1 : 0));
oldValue = value; }
if (value != oldValue)
{// Send in the new value
send(msgbuttonc.set(value==HIGH ? 1 : 0));
oldValue = value; }
temperature = temp0.read_temp(); // Read the temp
// { Serial.print("Current Temperature: ");
// Serial.println( temperature ); // Print the temperature to Serial
if (temperature != lastTemperature)
send(msg.setSensor(0).set(temperature, 1));
lastTemperature = temperature;
// }
// sleep(SLEEP_TIME);
}
j essaye de combiner plusieurs sketchs sur un seul arduino nano
celui d un capteur de temperature ;
https://github.com/mysensors/MySensorsA ... tureSensor
et de 3 boutons standard ;
https://github.com/mysensors/MySensorsA ... itchSensor
un seul des 3 boutons marche, pas les deux autres, et la sonde de temperature envoye bien des valeurs mais un peux trop souvant j aimerais qu elle les envoye que toutes les 1 secondes .....
/**
* REVISION HISTORY
* Version 1.0 - MrLynx
*
* DESCRIPTION
* MAX6875 High temperature sensor with range: -200 degC - +1300 degC
* http://forum.mysensors.org/topic/641/max6675
*
* Connect MAX6675 - Arduino
* CS0 - 4
* SO - 3
* SCLK - 5
* VCC - 5V
* GND - GND
*
*
* button - 6
*
*/
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <SPI.h>
#include <MySensors.h>
#include <MAX6675.h>
#include <Bounce2.h>
uint8_t CS0 = 4; // CS pin on MAX6675
uint8_t SO = 3; // SO pin of MAX6675
uint8_t SCLK = 5; // SCK pin of MAX6675
uint8_t units = 1; // Units to readout temp (0 = °F, 1 = °C)
float temperature = 0.0; // Temperature output variable
float lastTemperature;
unsigned long SLEEP_TIME = 5000;
bool metric = true;
MyMessage msg(0, V_TEMP);
// Initialize the MAX6675 Library for our chip
MAX6675 temp0(CS0, SO, SCLK, units);
#define CHILD_ID 3
#define CHILDb_ID 3
#define CHILDc_ID 3
#define BUTTON_PIN 6
#define BUTTONb_PIN 6
#define BUTTONc_PIN 6
Bounce debouncer = Bounce();
int oldValue=-1;
// Change to V_LIGHT if you use S_LIGHT in presentation below
MyMessage msgbutton(CHILD_ID,V_TRIPPED);
MyMessage msgbuttonb(CHILDb_ID,V_TRIPPED);
MyMessage msgbuttonc(CHILDc_ID,V_TRIPPED);
void setup()
{
// Setup the button
pinMode(BUTTON_PIN,INPUT);
pinMode(BUTTONb_PIN,INPUT);
pinMode(BUTTONc_PIN,INPUT);
// Activate internal pull-up
digitalWrite(BUTTON_PIN,HIGH);
digitalWrite(BUTTONb_PIN,HIGH);
digitalWrite(BUTTONc_PIN,HIGH);
// After setting up the button, setup debouncer
debouncer.attach(BUTTON_PIN);
debouncer.attach(BUTTONb_PIN);
debouncer.attach(BUTTONc_PIN);
debouncer.interval(5);
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Max6675 Temp Sensor", "1.0");
// Present all sensors to controller
present(0, S_TEMP);
// Register binary input sensor to gw (they will be created as child devices)
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
present(CHILD_ID, S_DOOR);
}
void loop()
{
debouncer.update();
// Get the update value
int value = debouncer.read();
if (value != oldValue)
{// Send in the new value
send(msgbutton.set(value==HIGH ? 1 : 0));
oldValue = value; }
if (value != oldValue)
{// Send in the new value
send(msgbuttonb.set(value==HIGH ? 1 : 0));
oldValue = value; }
if (value != oldValue)
{// Send in the new value
send(msgbuttonc.set(value==HIGH ? 1 : 0));
oldValue = value; }
temperature = temp0.read_temp(); // Read the temp
// { Serial.print("Current Temperature: ");
// Serial.println( temperature ); // Print the temperature to Serial
if (temperature != lastTemperature)
send(msg.setSensor(0).set(temperature, 1));
lastTemperature = temperature;
// }
// sleep(SLEEP_TIME);
}