Hello i am not good in programming. I found the Arduino Sketch Chooser but it doesnt work for me.
I want to choose the skechtes with an IR remote control. The IR remote control ist working.
Can somebody explain me how the Sketch Chooser works maybe example sketches.
The follwing codes i want to combine.
LED effect
/*
***Knight rider panel***
Simple code simulating knight rider's panel :)
LEDs are involved in PWM pins.
PWM pins are 3, 5, 6, 9, 10, 11 - will be in the array
created 2oo9
by Pavel Novak
http://pavel-novak.net
*/
int nextTime = 100; //Time delay between start next LED
int pause = 100; //pause
int ledPins[] = {19,18,17,16}; //array with PWM pins
int ledPinsLength = 4; //ledPins[] lenght
int x; //key of ledPins array
//setup() method
void setup() {
//initialize each pins as an output
for(int x = 0;x < ledPinsLength; x++) {
pinMode(ledPins[x], OUTPUT);
}
}
//loop() method
void loop() {
leftToRight(); //call left to right method
rightToLeft(); //call right to left method
}
//from left to right lighting method
void leftToRight() {
analogWrite(ledPins[0], 255); //turn on first LED
delay(pause); //pause
for(x = 1; x < ledPinsLength;x++) {
analogWrite(ledPins[x], 255); //primary LED
analogWrite(ledPins[x-1], 50); //secondary LED
delay(nextTime); //pause between next LED
turnOffLEDs(); //turn off all LEDs
}
}
//from right to left lighting method
void rightToLeft() {
analogWrite(ledPins[3], 255); //turn on first LED
delay(pause); //pause
for(x = ledPinsLength-2;x >= 0;x--) {
analogWrite(ledPins[x], 255); //primary LED
analogWrite(ledPins[x+1], 50); //secondary LED
delay(nextTime); //pause between next LED
turnOffLEDs(); //turn off all LEDs
}
}
//turn off all LEDs
void turnOffLEDs() {
for(int y = 0; y < ledPinsLength;y++) {
analogWrite(ledPins[y], 0);
}
}
Simon says game
/*Simon Says game by Robert Spann*/
int switch1 = 12; //The four button input pins
int switch2 = 11;
int switch3 = 10;
int switch4 = 9;
int led1 = 4; //LED pins
int led2 = 3;
int led3 = 2;
int led4 = 7;
int turn = 0;
int input1 = LOW;
int input2 = LOW;
int input3 = LOW;
int input4 = LOW;
int randomArray[100]; //Intentionally long to store up to 100 inputs (doubtful anyone will get this far)
int inputArray[100];
void setup() {
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(switch1, INPUT);
pinMode(switch2, INPUT);
pinMode(switch3, INPUT);
pinMode(switch4, INPUT);
randomSeed(analogRead(0)); //Added to generate "more randomness" with the randomArray for the output function
for (int y=0; y<=99; y++){ //For statement to loop through the output and input functions
output();
input();
}
}
void output() { //function for generating the array to be matched by the player
for (int y=turn; y <= turn; y++){ //Limited by the turn variable
Serial.println(""); //Some serial output to follow along
Serial.print("Turn: ");
Serial.print(y);
Serial.println("");
randomArray[y] = random(1, 5); //Assigning a random number (1-4) to the randomArray[y], y being the turn count
for (int x=0; x <= turn; x++){
Serial.print(randomArray[x]);
if (randomArray[x] == 1) { //if statements to display the stored values in the array
digitalWrite(led1, HIGH);
tone(8, 400, 300);
delay(300);
digitalWrite(led1, LOW);
delay(100);
}
if (randomArray[x] == 2) {
digitalWrite(led2, HIGH);
tone(8, 500, 300);
delay(300);
digitalWrite(led2, LOW);
delay(100);
}
if (randomArray[x] == 3) {
digitalWrite(led3, HIGH);
tone(8, 600, 300);
delay(300);
digitalWrite(led3, LOW);
delay(100);
}
if (randomArray[x] == 4) {
digitalWrite(led4, HIGH);
tone(8, 700, 300);
delay(300);
digitalWrite(led4, LOW);
delay(100);
}
}
}
}
void input() { //Function for allowing user input and checking input against the generated array
for (int x=0; x <= turn;){ //Statement controlled by turn count
input1 = digitalRead(switch1);
input2 = digitalRead(switch2);
input3 = digitalRead(switch3);
input4 = digitalRead(switch4);
if (input1 == HIGH){ //Checking for button push
digitalWrite(led1, HIGH);
tone(8, 400, 300);
delay(300);
digitalWrite(led1, LOW);
inputArray[x] = 1;
delay(50);
Serial.print(" ");
Serial.print(1);
if (inputArray[x] != randomArray[x]) { //Checks value input by user and checks it against
fail(); //the value in the same spot on the generated array
} //The fail function is called if it does not match
x++;
}
if (input2 == HIGH){
digitalWrite(led2, HIGH);
tone(8, 500, 300);
delay(300);
digitalWrite(led2, LOW);
inputArray[x] = 2;
delay(50);
Serial.print(" ");
Serial.print(2);
if (inputArray[x] != randomArray[x]) {
fail();
}
x++;
}
if (input3 == HIGH){
digitalWrite(led3, HIGH);
tone(8, 600, 300);
delay(300);
digitalWrite(led3, LOW);
inputArray[x] = 3;
delay(50);
Serial.print(" ");
Serial.print(3);
if (inputArray[x] != randomArray[x]) {
fail();
}
x++;
}
if (input4 == HIGH){
digitalWrite(led4, HIGH);
tone(8, 700, 300);
delay(300);
digitalWrite(led4, LOW);
inputArray[x] = 4;
delay(50);
Serial.print(" ");
Serial.print(4);
if (inputArray[x] != randomArray[x]) {
fail();
}
x++;
}
}
delay(500);
turn++; //Increments the turn count, also the last action before starting the output function over again
}
void fail() { //Function used if the player fails to match the sequence
for (int y=0; y<=5; y++){ //Flashes lights for failure
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
tone(8, 900, 400);
delay(400);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
delay(200);
}
delay(500);
turn = -1; //Resets turn value so the game starts over without need for a reset button
}
void loop() { //Unused void loop(), though for some reason it doesn't compile without this /shrug
}
The codes are not from me but a little bit changed an working.
Sorry for my bad engl I am from Germany. ![]()
Thanks