The program below sweeps through frequencies 1hz to 6 hz and then back to 1hz. I've been trying to incororate code to use a push buttom to turn the arduino on and off.
I have seen programs that turn an LED on and off but am having difficulty incororating them into this program.
I'm not a software engineer so would be very grateful for any help
uint8_t freq_Hz[6] ={1,2,3,4,5,6};// Set up an array for the 6 frequencies
uint8_t pulses =25; // Number of pulses per frequecncy
uint8_t duty =10; // Sets Duty cycle
unsigned long period_ms;
unsigned long OnTime;
int out_pin=4;
int out_pin1 =3;
int Led1=8;
int Led2=9;
void setup() {
// put your setup code here, to run once:
{
pinMode(out_pin,OUTPUT);
pinMode(out_pin1, OUTPUT);
pinMode(Led1,OUTPUT);
pinMode(Led2,OUTPUT);
}
}
void loop()
// put your main code here, to run repeatedly:
{
for (uint8_t i=0;i<6;++i){ //Cycle through the 6 elements of freq_hz array
period_ms =1000/freq_Hz[i]; // Calculate the period in ms of freq_hz
OnTime = (period_ms*duty)/100; // Calculate from % duty cycle ON Time in ms
for(uint8_t j=0; j<pulses;++j){ // loops frequency x pulses at each frequency
digitalWrite (out_pin,HIGH);
digitalWrite (out_pin1,HIGH);
digitalWrite (Led1,HIGH);
digitalWrite (Led2,HIGH);
delay(OnTime);
digitalWrite(out_pin,LOW);
digitalWrite(out_pin1,LOW);
digitalWrite(Led1,LOW);
digitalWrite(Led2,LOW);
delay(period_ms - OnTime);
}
}
}