Anyone any good at programming ?
my son did a bit of work for me, but i am failing to get my code to compile...
heres what i want to do...
the first code is for three leds running a sequence led 1 on running the pattern sequence, led 2 on running the pattern sequence, led 3 on running the pattern sequence, then all 3 leds come on together the reason for this is i wanted a sequence that would keep some 10w leds nice and cool.... and i can play about with the timings on off etc...
this code...
/*
Blink
10 Watt strobe sequence
*/
#define LED1 (int)0
#define LED2 (int)1
#define LED3 (int)2
// the setup function runs once when you press reset or power the board
void setup() {
// Set Led1,2 as output on digital pin 12,13
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
}
// Pattern Command set the strobe pattern hi,lo
void loop() {
int pattern[8] = {30,400,30,400,10,300,10,1600};
for (int i = 0; i < 4; i++) {
digitalWrite(LED2, HIGH);
delay(pattern[i*2]);
digitalWrite(LED2, LOW);
delay(pattern[i*2+1]);
}
for (int f = 0; f < 4; f++) {
digitalWrite(LED1, HIGH);
delay(pattern[f*2]);
digitalWrite(LED1, LOW);
delay(pattern[f*2+1]);
}
for (int g = 0; g < 4; g++) {
digitalWrite(LED3, HIGH);
delay(pattern[g*2]);
digitalWrite(LED3, LOW);
delay(pattern[g*2+1]);
}
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
delay(400);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
delay(2000);
}
anyway to make this even better, i want to add a further no of sequences maybe 3 or 4 or 5 switchable with a switch on a input pin...
like this...
int pattern = 0;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(0, OUTPUT); //LED on Model B
pinMode(1, OUTPUT); //LED on Model A or Pro
pinMode(2, INPUT);
}
void patternOne() {
int pattern[12] = {25,450,25,450,25,450,10,350,10,350,10,1700};
for (int i = 0; i < 6; i++) {
digitalWrite(0, HIGH);
digitalWrite(1, HIGH);
delay(50);
digitalWrite(0, LOW);
digitalWrite(1, LOW);
delay(50);
}
void patternTwo() {
digitalWrite(0, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(1, HIGH);
delay(300); // wait for a second
digitalWrite(0, LOW); // turn the LED off by making the voltage LOW
digitalWrite(1, LOW);
delay(300); // wait for a second
}
void patternThree() {
digitalWrite(0, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(1, HIGH);
delay(1000); // wait for a second
digitalWrite(0, LOW); // turn the LED off by making the voltage LOW
digitalWrite(1, LOW);
delay(1000); // wait for a second
}
// the loop routine runs over and over again forever:
void loop() {
if (digitalRead(2) == LOW) {
digitalWrite(0, HIGH);
pattern = (pattern + 1)%3;
delay(200);
digitalWrite(0, LOW);
}
switch(pattern) {
case 0: patternOne();
break;
case 1: patternTwo();
break;
case 2: patternThree();
break;
}
}
now the both above sketches will compile seperately fine...
i want to add a pattern command to each of the switchable sequences, so in essence merging code 1 and code2...
so i can have 3,4,5 programmable strobe patterns that i can alter with a switch... each of the strobe patterns need need to have a pattern command i can alter in software... so eventually i can pick a long sequence or a simple on off sequence etc... can someone please merge the two codes together for me
thanks....