unnamed file

C/C++

3x3 LED

Guest

Download Edit

void setup(){
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(13, OUTPUT);
// Serial.begin(9600);
// Serial.println("Setup ok.");
}
// ############
void setOn(int x, int y){
digitalWrite(2+y+x*3, HIGH);
}
// ############
void setOff(int x, int y){
digitalWrite(2+y+x*3, LOW);
}
// ############
void moveLeft(){
// Serial.println("Begin of moveLeft().");
for (int checkPin = 10; checkPin >= 2; checkPin--){
// Serial.print("Entering for() with checkPin = ");
// Serial.println(checkPin);
if(digitalRead(checkPin)==HIGH){
int onlinePin = checkPin+3;
digitalWrite(checkPin, LOW);
digitalWrite(onlinePin, HIGH);
}
}
}
// ############
void moveLeftOut(){ //Nach Links weg
moveLeft();
delay(300);
moveLeft();
delay(300);
moveLeft();
}
// ############
void setAllOn(){
for(int i=2; i<= 10; i++){
digitalWrite(i, HIGH);
}
}
// ############
void setAllOff(){
for(int i=2; i<= 10; i++){
digitalWrite(i, LOW);
}
}
// ############
void negativ(){
for(int checkPin=2; checkPin <= 10; checkPin++){
if(digitalRead(checkPin)==HIGH){
digitalWrite(checkPin, LOW);
}
else
{
digitalWrite(checkPin, HIGH);
}
}
}
// ############
void drehen(){
}
void loop(){
setAllOff(); //Alles nur schöne Animationen
delay(200);
setOn(0,0);
delay(500);
setOn(1,2);
delay(500);
negativ();
delay(500);
moveLeft();
delay(500);
negativ();
delay(500);
moveLeftOut();
setAllOff();
delay(500);
setAllOff();
delay(500); //Sieht schöner aus.
// Serial.println("Enter loop.");
setOn(1,1);
setOn(0,1);
setOn(2,1);
setOn(1,0);
delay(1000);
moveLeftOut(); //und wech damit
delay(1000);
for(int i=0;i<=2;i++){
for(int j=0;j<=2;j++){
setOn(i,j);
delay(100);
setOff(i,j);
delay(100);
}
}
for(int j=0;j<=2;j++){
for(int i=0;i<=2;i++){
setOn(i,j);
delay(100);
setOff(i,j);
delay(100);
}
}
moveLeftOut();
delay(1000);
setOn(1,0);
setOn(2,2);
delay(1000);
moveLeftOut();
setAllOn();
delay(500);
moveLeftOut();
delay(1000); //SCHNARCH
setOn(1,1);
setOn(0,1);
setOn(2,1);
setOn(1,0);
setOn(1,2);
delay(500);
negativ();
delay(1000);
negativ();
delay(250);
negativ();
delay(250);
negativ();
delay(250);
negativ();
delay(250);
negativ();
delay(250);
setOn(0,0);
setOn(0,1);
setOn(0,2);
setOn(1,0);
setOn(2,0);
setOn(1,1);
setOn(2,1);
setOn(2,2);
}