I make a simple circuit with the use of Arduino and it works well, having an IC like ATTiny is good but i have a small space on my PVC Tube for DC-DC Step Down.
My goal is to make a flashlight that have a secondary switch
- Switch 1 (Toggle Switch) - Turn Lights On or Off
- Switch 2 (Momentary Switch) - Turn Lights On even if switch 1 is Off, Turn Lights Off even the switch 1 is On.
I have this code
void setup()
{
Serial.begin(9600);
pinMode(2,INPUT_PULLUP); //
pinMode(13, OUTPUT);
pinMode(3,INPUT_PULLUP);
}
void loop()
{
int sensorValue = digitalRead(2);
int sensorValue3 = digitalRead(3);
//Serial.println(sensorValue3, DEC);
if (sensorValue == HIGH){
//OFF via toggle
if (sensorValue3 == LOW){
// ON via button if OFF via toggle
digitalWrite(13, HIGH);
}else{
// OFF
digitalWrite(13, LOW);
}
}else if(sensorValue == LOW){
//ON via toggle
if (sensorValue3 == LOW){
digitalWrite(13, LOW);
}else{
digitalWrite(13, HIGH);
}
}
}
Ive seen an Oscillator with a relay but cant make it work.
if (sensorValue3 == LOW){ digitalWrite(13, LOW); }else{ digitalWrite(13, HIGH); }
........... this produces the same resultdigitalWrite(13, sensorValue3 );
\$\endgroup\$