Show
Ignore:
Timestamp:
05/17/09 22:25:10 (3 years ago)
Author:
njw
Message:

debouncing; more concrete testing...

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • de.wigbels.avr/sketchbook/hothotheat/hothotheat.pde

    r21 r22  
    2424#include <pins_butterfly.h> 
    2525 
    26 int inputPin = PBPIN4; 
     26int inputReed = PBPIN4; 
     27int outputLED = PBPIN6; 
     28 
    2729int value = 0; 
     30int debounce = 0; 
    2831 
    2932 
    3033void setup() { 
    3134  Serial.begin(9600);  
    32   pinMode(inputPin, INPUT); 
     35  pinMode(inputReed, INPUT); 
     36  pinMode(outputLED, OUTPUT); 
    3337} 
    3438 
    35 void getSamples(){ 
     39int getSamples(){ 
    3640  Serial.print("1"); 
    3741  Serial.print("\t"); 
     
    3943  Serial.println();   
    4044 
    41   value = digitalRead(inputPin); 
    42   if (value == HIGH) { 
    43     Serial.println("HIGH"); 
     45  // switchtime of reed is 18 ms including debouncing... 
     46  value = digitalRead(inputReed); 
     47  delay(20); 
     48  debounce = digitalRead(inputReed); 
     49  if (value==debounce) { 
     50    if (value == HIGH) { 
     51      Serial.println("HIGH"); 
     52      return 1; 
     53    } 
     54    else { 
     55      Serial.println("LOW"); 
     56      return 0; 
     57    } 
    4458  } 
    45   else { 
    46     Serial.println("LOW"); 
    47   }   
    4859} 
    4960 
    5061void loop() {   
    5162  TempSense.overSample = true; 
    52   getSamples(); 
    53   delay(400); 
     63  if(getSamples()==1) { 
     64    digitalWrite(outputLED, HIGH); 
     65  } else { 
     66    digitalWrite(outputLED, LOW); 
     67  } 
     68 
     69  delay(100); 
    5470}