Hi,
I'm new so I think it'll be polite to introcude myself. I'm mostly into analog circuit I build effect circuit for electric guitar , some synth cicuit sometimes and tube amps as well
I decided to jump into the binary world after I built the Shruthi , a little digital/analog DIY synth with an AVR µC as a brain. I was really amazed by so much possibilities in so little space . So it'll be wrong to miss this opportunity of learning programming and µC.
I've never write a code or touch a µC , so I've everything to learn. No problem , I like learning
anyway, here's the topic .
for education purpose I wanted to create a switching program . I added a LCD display to add (relative) complexity. The idea is simple , there's one input , the button and two outputs .
-first mode, a classic ON/OFF switching , the ouput 1 goes low to high.
-second mode, the tricky one : if the button is pressed twice quickly (say 1/2 second) it actives the second output . With no effect
on the first ouput.
to put the second output low , the same operation has to be done. two quick hits.
Here's what I came up with so far
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int inPin = 9;
int outPin = 8;
int state =LOW;
int reading;
int previous = LOW;
long time = 0;
long debounce = 150;
void setup()
{
pinMode(inPin, INPUT);
pinMode(outPin, OUTPUT);
lcd.print("BYPASS");
}
void loop()
{
reading = digitalRead(inPin);
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH){
state = LOW;
lcd.clear();
lcd.print("BYPASS");}
else{
state = HIGH;
time = millis();
lcd.clear();
lcd.print("EFFECT ON");}
}
digitalWrite(outPin,state);
previous = reading;
}
it's silghty modifed version of an exemple.
The question is how adding the second mode ?. I thought about an interrupt with the trigger based on a reading of two hits.
if they're short enought the second mode is actived (or put low). but the deboucing also as to be considered in the calculation.
I'm still looking for the right function and trying codes, but maybe some members could lead me to direction where I could find useful imformations ?
thanks for reading