hello everyone
I have a project going on where some LEDs are turned on/off and a signal is transmitted via those RF 315/433 MHz Trans-receiver. Some parameters are controlled with 3 pushbuttons.
Here is the thing: push buttons readings are ok with a testing code where I just press the buttons and get the readings. BUT if implement the rest of the code, push button readings become unstable (bounce).
More precisely the conflict occurs with the virtualwire library: I figured out adding parts of the final code to the testing code, one at the time. Every goes nuts with the setup instuction of the virtualwire library
any suggestions? any similar experience?
I also tried debouncing libraries as bounce2, but i did not work for me
here is the code
#include <TimerFreeTone.h>
#include <SoftPWM.h>
#include <VirtualWire.h>
// A
// ---
// B | | C
// -D-
// E | | F
// ---
// G
#define segApin 8
#define segBpin 7
#define segCpin 6
#define segDpin 5
#define segEpin 4
#define segFpin 3
#define segGpin 2
#define tonePin 12
#define onoff_btnPin 9
#define plus_btnPin 11 // inizializzazioni PIN bottoni
#define mins_btnPin 10 // inizializzazioni PIN bottoni
#define trxPin 13
int mode_btnState[] = {1,1}; int mode_btn = 1; // inizializzazioni bottoni
int plus_btnState[] = {1,1}; int plus_btn = 1; // inizializzazioni bottoni
int mins_btnState[] = {1,1}; int mins_btn = 1; // inizializzazioni bottoni
int onoff_btnState[] = {1,1}; int onoff_btn = 1; // inizializzazioni bottoni
int dT = 1000; // delta T di lampeggiamento in millisecondi
unsigned long t0; // t0 per durata alternate
int toneCount = 1; // frequenza suono del buzzer
int toneFreq = 3000; // frequenza del buzzer
int toneLast = 75; // durata del tone
int alt = 0; // alterno? 0 o 1
int num; // numero da stampare
int lumH = 100;
int lumL = 1;
void setup(){
TimerFreeTone( tonePin, toneFreq , toneLast );
Serial.begin(9600);
// PIN MODES
pinMode( plus_btnPin, INPUT_PULLUP); pinMode(mins_btnPin, INPUT_PULLUP);
pinMode(onoff_btnPin, INPUT_PULLUP); pinMode(tonePin,OUTPUT);
// SETTAGGI DI TRASMISSIONE
vw_set_tx_pin(trxPin); //configurazione pin trasmissione
//vw_set_ptt_pin(transmit_en_pin); // settaggio pin enable-transmission
vw_set_ptt_inverted(true); // settaggio polarità PUSH-TO-TALK
vw_setup(2000);
//Set UP PWM TEST
SoftPWMBegin(); // Initializes the library - sets up the timer and other tasks
}
void loop(){
// TASTI INIZIO LOOP - aggiornamento stato attuale
plus_btnState[1] = btnRead( plus_btnPin, plus_btnState[0]);
mins_btnState[1] = btnRead( mins_btnPin, mins_btnState[0]);
onoff_btnState[1] = btnRead(onoff_btnPin, onoff_btnState[0]);
Serial.print(dT);Serial.print("\t");
Serial.print(onoff_btnState[1]);Serial.print("\t");
Serial.print( mins_btnState[1]);Serial.print("\t");
Serial.print( plus_btnState[1]);Serial.print("\t");
Serial.println();
if(onoff_btn == 1){
// TASTI - esecuzione al cambio di stato
if( ( digitalRead(plus_btnPin) == LOW && plus_btnState[1] != plus_btnState[0] ) && ( digitalRead(mins_btnPin) == LOW && mins_btnState[1] != mins_btnState[0] )) {
mode_btn = 1-mode_btn ;
t0 = millis();
num = random(0,10);
if(mode_btn==1){StartSequence(dT);}
}
if( plus_btnState[1] == 1 && plus_btnState[1] != plus_btnState[0] ) {if(dT>100){dT = dT + 100;} }
if( mins_btnState[1] == 1 && mins_btnState[1] != mins_btnState[0] ) {if(dT>100){dT = dT - 100;} }
// REST OF THE CODE
//TASTI FINE LOOP - aggiornamento stato precedente
mins_btnState[0] = mins_btnState[1];
plus_btnState[0] = plus_btnState[1];
onoff_btnState[0] = onoff_btnState[1];
}