I have a project were I have a 1hhz frequency output with an Ontime and an off time, when I press a putton and hold it the frequency changes to 10khz ie using an if statment to do this.
Now what I want to do is use a 6 pole switch connected to d5,d6,d7,d8,d9,d10configured as inputs
a high on any of these produces a unique on off time on say d3 configured as an output.
This is my code for 1hz and 10hz outputs.
int OutputState=LOW;
unsigned long previousMillis1=0;
long OnTime;// on time of waveform
long OffTime;// off time of waveform
int pushbutton=6
;
void setup() {
// put your setup code here, to run once:
pinMode(Output,OUTPUT);
pinMode(pushbutton,INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
unsigned long currentMillis=millis();
if (digitalRead (pushbutton==HIGH))
{
OnTime=50;
OffTime=950;
//Serial.print(OnTime);
}else {
OnTime =10;
OffTime= 90;
}
Serial.println(OnTime);
if ((OutputState==HIGH)&&(currentMillis-previousMillis1>=OnTime))
{
OutputState =LOW;
previousMillis1=currentMillis;
digitalWrite(Output,OutputState);
}
else if ((OutputState==LOW)&&(currentMillis-previousMillis1>=OffTime))
{
OutputState=HIGH;
previousMillis1=currentMillis;
digitalWrite(Output,OutputState);
}
}
Can someone explain the simplest way of doing this