Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

LED 35-Dot-Matrix

26. September 2012

Über zwei Bit-Shift Register wird eine LED-Matrix angesteuert zur Ausgabe von Zahlen. Mit 2 Buttons können die Zahlenwerte vergrössert oder verkleinert werden. Code: #define LATCH_PIN 8 #define CLOCK_PIN 12 #define DATA_PIN 11 #define Button_1 3 #define Button_2 2 int i = 0; int t = 0; void setup() { pinMode(LATCH_PIN, OUTPUT); pinMode(CLOCK_PIN, OUTPUT); pinMode(DATA_PIN, OUTPUT); pinMode(Button_1, INPUT); pinMode(Button_2, INPUT); Serial.begin(9600); } void loop() { t++; if(t >100) { if(digitalRead(Button_1) == HIGH) { i++; } else if(digitalRead(Button_2) == HIGH) { i--; } else if(digitalRead(Button_2) == HIGH&&digitalRead(Button_1) == HIGH) { i=0; } t=0; } if (i9) { i=0; } if(i==0) { Nummer_0(); } else if(i==1) { Nummer_1(); } else if(i==2) { Nummer_2(); } else if(i==3) { Nummer_3(); } else if(i==4) { Nummer_4(); } else if(i==5) { Nummer_5(); } else if(i==6) { Nummer_6(); } else if(i==7) { Nummer_7(); } else if(i==8) { Nummer_8(); } else if(i==9) { Nummer_9(); } } void Nummer_1() { Led_C2(); Led_B3(); Led_A4(); Led_B4(); Led_C4(); Led_D4(); Led_E4(); Led_F4(); Led_G4(); } void Nummer_2() { Led_B1(); Led_A2(); Led_A3(); Led_A4(); Led_B5(); Led_C5(); Led_D4(); Led_E3(); Led_D4(); Led_E3(); Led_F2(); Led_G1(); Led_G2(); Led_G3(); Led_G4(); Led_G5(); } void Nummer_3() { Led_B1(); Led_A2(); Led_A3(); Led_A4(); Led_B5(); Led_C5(); Led_D4(); Led_D4(); Led_D3(); Led_E5(); Led_F5(); Led_G4(); Led_G3(); Led_G2(); Led_F1(); } void Nummer_4() { Led_A4(); Led_B4(); Led_C4(); Led_D4(); Led_E4(); Led_F4(); Led_G4(); Led_E5(); Led_E3(); Led_E2(); Led_E1(); Led_D1(); Led_C2(); Led_B2(); Led_A3(); } void Nummer_5() { Led_A1(); Led_A2(); Led_A3(); Led_A4(); Led_A5(); Led_B1(); Led_C1(); Led_D1(); Led_C2(); Led_C3(); Led_C4(); Led_D5(); Led_E5(); Led_F5(); Led_G4(); Led_G3(); Led_G2(); Led_F1(); } void Nummer_6() { Led_A2(); Led_A3(); Led_A4(); Led_B5(); Led_B1(); Led_C1(); Led_D1(); Led_E1(); Led_F1(); Led_G2(); Led_G3(); Led_G4(); Led_F5(); Led_E5(); Led_D4(); Led_D3(); Led_D2(); } void Nummer_7() { Led_A1(); Led_A2(); Led_A3(); Led_A4(); Led_A5(); Led_B5(); Led_C5(); Led_D4(); Led_E4(); Led_F3(); Led_G3(); } void Nummer_8() { Led_A2(); Led_A3(); Led_A4(); Led_B5(); Led_B1(); Led_C1(); Led_C5(); Led_D2(); Led_D3(); Led_D4(); Led_E5(); Led_E1(); Led_F5(); Led_F1(); Led_G2(); Led_G3(); Led_G4(); } void Nummer_9() { Led_A2(); Led_A3(); Led_A4(); Led_B5(); Led_B1(); Led_C1(); Led_C5(); Led_D2(); Led_D3(); Led_D4(); Led_E5(); Led_D5(); Led_F5(); Led_F1(); Led_G2(); Led_G3(); Led_G4(); } void Nummer_0() { Led_A2(); Led_A3(); Led_A4(); Led_B5(); Led_B1(); Led_C1(); Led_C5(); Led_D1(); Led_E1(); Led_E5(); Led_D5(); Led_F5(); Led_F1(); Led_G2(); Led_G3(); Led_G4(); } void Led_A1() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 127); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 128); digitalWrite(LATCH_PIN, HIGH); } void Led_A2() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 191); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 128); digitalWrite(LATCH_PIN, HIGH); } void Led_A3() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 216); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 128); digitalWrite(LATCH_PIN, HIGH); } void Led_A4() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 232); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 128); digitalWrite(LATCH_PIN, HIGH); } void Led_A5() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 240); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 128); digitalWrite(LATCH_PIN, HIGH); } void Led_B1() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 127); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 64); digitalWrite(LATCH_PIN, HIGH); } void Led_B2() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 191); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 64); digitalWrite(LATCH_PIN, HIGH); } void Led_B3() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 216); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 64); digitalWrite(LATCH_PIN, HIGH); } void Led_B4() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 232); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 64); digitalWrite(LATCH_PIN, HIGH); } void Led_B5() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 240); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 64); digitalWrite(LATCH_PIN, HIGH); } void Led_C1() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 127); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 32); digitalWrite(LATCH_PIN, HIGH); } void Led_C2() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 191); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 32); digitalWrite(LATCH_PIN, HIGH); } void Led_C3() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 216); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 32); digitalWrite(LATCH_PIN, HIGH); } void Led_C4() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 232); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 32); digitalWrite(LATCH_PIN, HIGH); } void Led_C5() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 240); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 32); digitalWrite(LATCH_PIN, HIGH); } void Led_D1() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 127); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 16); digitalWrite(LATCH_PIN, HIGH); } void Led_D2() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 191); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 16); digitalWrite(LATCH_PIN, HIGH); } void Led_D3() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 216); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 16); digitalWrite(LATCH_PIN, HIGH); } void Led_D4() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 232); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 16); digitalWrite(LATCH_PIN, HIGH); } void Led_D5() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 240); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 16); digitalWrite(LATCH_PIN, HIGH); } void Led_E1() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 127); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 8); digitalWrite(LATCH_PIN, HIGH); } void Led_E2() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 191); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 8); digitalWrite(LATCH_PIN, HIGH); } void Led_E3() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 216); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 8); digitalWrite(LATCH_PIN, HIGH); } void Led_E4() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 232); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 8); digitalWrite(LATCH_PIN, HIGH); } void Led_E5() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 240); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 8); digitalWrite(LATCH_PIN, HIGH); } void Led_F1() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 127); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 4); digitalWrite(LATCH_PIN, HIGH); } void Led_F2() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 191); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 4); digitalWrite(LATCH_PIN, HIGH); } void Led_F3() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 216); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 4); digitalWrite(LATCH_PIN, HIGH); } void Led_F4() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 232); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 4); digitalWrite(LATCH_PIN, HIGH); } void Led_F5() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 240); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 4); digitalWrite(LATCH_PIN, HIGH); } void Led_G1() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 127); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 2); digitalWrite(LATCH_PIN, HIGH); } void Led_G2() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 191); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 2); digitalWrite(LATCH_PIN, HIGH); } void Led_G3() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 216); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 2); digitalWrite(LATCH_PIN, HIGH); } void Led_G4() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 232); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 2); digitalWrite(LATCH_PIN, HIGH); } void Led_G5() { digitalWrite(LATCH_PIN, LOW); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 240); shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, 2); digitalWrite(LATCH_PIN, HIGH); } Resultat: