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.

Schritt für Schritt

25. September 2012

Grössere Probleme hatte ich keine. Sachen wie "Output-setzen-vergessen" haben Zeit gekostet, stellen aber keine nachhaltige Herausforderung dar.

#define LATCH_PIN 8 //Pin zu ST_CP vom 74HC595
 #define CLOCK_PIN 12 //Pin zu SH_CP vom 74HC595
 #define DATA_PIN 11 //Pin zu DS vom 74HC595
 #define LED_9 6
 #define LED_10 7
 #define TASTER_PLUS 2
 #define TASTER_MINUS 3

int lastButtonState[] = {1,1};
 long lastDebounceTime = 0; // Die letzte Zeit als der Taster gedrückt wurde
 long debounceDelay = 50; // Die Verzögerung des Tasters
 int counter = 0;

boolean buttonPlusPressed = false;
 boolean buttonMinusPressed = false;

void setup()
 {
 pinMode(TASTER_PLUS, INPUT);
 digitalWrite(TASTER_PLUS, HIGH);
 pinMode(TASTER_MINUS, INPUT);
 digitalWrite(TASTER_MINUS, HIGH);

pinMode(LATCH_PIN, OUTPUT);
 pinMode(CLOCK_PIN, OUTPUT);
 pinMode(DATA_PIN, OUTPUT);
 pinMode(LED_9, OUTPUT);
 pinMode(LED_10, OUTPUT);

Serial.begin(9600);
 }

void loop()
 {
 if(digitalRead(TASTER_PLUS) == LOW && buttonPlusPressed == false)
 {
 buttonPlusPressed = true;
 lastDebounceTime = millis();
 Serial.print("last Debounce: ");
 Serial.println(lastDebounceTime);
 }

if(digitalRead(TASTER_MINUS) == LOW && buttonMinusPressed == false)
 {
 buttonMinusPressed = true;
 lastDebounceTime = millis();
 Serial.print("last Debounce: ");
 Serial.println(lastDebounceTime);
 }

if(millis()-lastDebounceTime > debounceDelay && buttonPlusPressed == true || millis()-lastDebounceTime > debounceDelay && buttonMinusPressed == true)
 {
 // AKtion

if(digitalRead(TASTER_PLUS) == LOW && counter < 9 ){
 counter++;
 }

if(digitalRead(TASTER_MINUS) == LOW && counter > 0){
 counter--;
 }

Serial.print("counter: ");
 Serial.println(counter);
 delay(200);
 }

if(counter registerWrite(counter, HIGH);
 }

if(counter == 8){

registerWrite(7, LOW);
 digitalWrite(LED_10, LOW);
 digitalWrite(LED_9, HIGH);
 }

if(counter == 9){
 registerWrite(7, LOW);
 digitalWrite(LED_9, LOW);
 digitalWrite(LED_10, HIGH);
 }

if(digitalRead(TASTER_PLUS) == HIGH)
 {
 buttonPlusPressed = false;
 }

if(digitalRead(TASTER_MINUS) == HIGH)
 {
 buttonMinusPressed = false;
 }
 }

void registerWrite(int _whichPin, int _whichState)
 {

byte bitsToSend = 0; // Dieses Byte hat acht Bits also: 00000000

digitalWrite(LATCH_PIN, LOW);
 digitalWrite(LED_9, LOW);
 digitalWrite(LED_10, LOW);

bitWrite(bitsToSend, _whichPin, _whichState); // Hier wird das entsprechende Bit im Byte gesetzt (z.B. 00100000)

shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, bitsToSend);

digitalWrite(LATCH_PIN, HIGH);

}

&nbsp;