Hi,
I wanted to use Arduino Uno to run multiple tasks and I am new to this. I understand that Scheduler can do this job in Arduino Uno but it didn't work for me. Would you please guide me how to do it.
My project is this,
- need a continuous 1KHz 50% duty cycle pulses.
- need to sequence up and down a 2 power supplies
#include <Scheduler.h>
/*********************
Power sequencer with 1Khz Clock
**********************/
// Define pins
const int togUp = 8; //Toggle switch - up
const int ch1Pin = 0;
const int ch2Pin = 1;
const int ch3Pin = 2;
const int ch4Pin = 3;
const int ch5Pin = 4;
const int ch6Pin = 5;
const int ch7Pin = 6;
const int ch8Pin = 7;
//Clock out pin
int outPin = A0;
/*******************************************/
void setup()
{
pinMode(togUp, INPUT_PULLUP);
pinMode(ch1Pin, OUTPUT);
pinMode(ch2Pin, OUTPUT);
pinMode(ch3Pin, OUTPUT);
pinMode(ch4Pin, OUTPUT);
pinMode(ch5Pin, OUTPUT);
pinMode(ch6Pin, OUTPUT);
pinMode(ch7Pin, OUTPUT);
pinMode(ch8Pin, OUTPUT);
pinMode(outPin, OUTPUT); // sets the A0 pin as clock output
digitalWrite(ch1Pin, LOW);
digitalWrite(ch2Pin, LOW);
digitalWrite(ch3Pin, LOW);
digitalWrite(ch4Pin, LOW);
digitalWrite(ch5Pin, LOW);
digitalWrite(ch6Pin, LOW);
digitalWrite(ch7Pin, LOW);
digitalWrite(ch8Pin, LOW);
Scheduler.startLoop(loop1);
}
/*************************************************
Main loop to generate Clock & check switch
**************************************************/
void loop()
{
// 1Khz Clock Generation
digitalWrite(outPin, HIGH); // sets the pin on
delayMicroseconds(500); // pauses for 50 microseconds
digitalWrite(outPin, LOW); // sets the pin off
delayMicroseconds(500); // pauses for 50 microseconds
}
void loop1 (){
//Check for toggle up
int toggleState = digitalRead(togUp);
if (toggleState == 0)
sequenceUp();
else
sequenceDn();
yield();
}
/*************************************************
sequence UP
**************************************************/
void sequenceUp()
{
int ch1;
int ch2;
int ch3;
int ch4;
int ch5;
int ch6;
int ch7;
int ch8;
//SequenceUp Delay in milliseconds
ch1 = (100);
ch2 = (100);
ch3 = (100);
ch4 = (100);
ch5 = (100);
ch6 = (100);
ch 7 = (100 );
//Activate the pins
digitalWrite(ch1Pin,HIGH);
delay(ch1);
digitalWrite(ch2Pin,HIGH);
delay(ch2);
digitalWrite(ch3Pin,HIGH);
delay(ch3);
digitalWrite(ch4Pin,HIGH);
delay(ch4);
digitalWrite(ch5Pin,HIGH);
delay(ch5);
digitalWrite(ch6Pin,HIGH);
delay(ch6);
digitalWrite(ch7Pin,HIGH);
delay(ch7);
digitalWrite(ch8Pin,HIGH);
}
/*************************************************
sequence Down
**************************************************/
void sequenceDn()
{
int ch1;
int ch2;
int ch3;
int ch4;
int ch5;
int ch6;
int ch7;
int ch8;
//SequenceUp Delay in milliseconds
ch1 = (100);
ch2 = (100);
ch3 = (100);
ch4 = (100);
ch5 = (100);
ch6 = (100);
ch7 = (100);
digitalWrite(ch8Pin,LOW);
delay(ch7);
digitalWrite(ch7Pin,LOW);
delay(ch6);
digitalWrite(ch6Pin,LOW);
delay(ch5);
digitalWrite(ch5Pin,LOW);
delay(ch4);
digitalWrite(ch4 Pin,LOW) ;
delay(ch3);
digitalWrite(ch3Pin,LOW);
delay(ch2);
digitalWrite(ch2Pin,LOW);
delay(ch1);
digitalWrite(ch1Pin,LOW);
}
Please help.