Last change
on this file since 4aaeb66 was
4aaeb66,
checked in by njw <njw@…>, 15 years ago
|
debouncing; more concrete testing...
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Rev | Line | |
---|
[454b95c] | 1 | /* |
---|
| 2 | * HotHotHeat |
---|
| 3 | * |
---|
[78394ea] | 4 | * Compile with the Arduino IDE (http://arduino.cc); is deployed against a |
---|
| 5 | * Atmel Butterfly - so you also need the Butteruino project |
---|
| 6 | * (http://code.google.com/p/butteruino/) |
---|
| 7 | * |
---|
| 8 | * ...will |
---|
[454b95c] | 9 | * 1) Read the Butterfly temperature sensor and output |
---|
| 10 | * the result permanently to UART. |
---|
| 11 | * |
---|
| 12 | * 2) Read a reed sensor and output |
---|
| 13 | * the result permanently to UART |
---|
| 14 | * |
---|
[78394ea] | 15 | * Contact: Norbert Wigbels |
---|
| 16 | * (http://foobla.wigbels.de/uber-foobla/) |
---|
[454b95c] | 17 | * |
---|
| 18 | * Format: <# of Sensor> <data> |
---|
| 19 | * Example: 1; Temperature in Celsius |
---|
| 20 | * tbd. |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | #include <butterfly_temp.h> |
---|
| 24 | #include <pins_butterfly.h> |
---|
| 25 | |
---|
[4aaeb66] | 26 | int inputReed = PBPIN4; |
---|
| 27 | int outputLED = PBPIN6; |
---|
| 28 | |
---|
[454b95c] | 29 | int value = 0; |
---|
[4aaeb66] | 30 | int debounce = 0; |
---|
[454b95c] | 31 | |
---|
| 32 | |
---|
| 33 | void setup() { |
---|
| 34 | Serial.begin(9600); |
---|
[4aaeb66] | 35 | pinMode(inputReed, INPUT); |
---|
| 36 | pinMode(outputLED, OUTPUT); |
---|
[454b95c] | 37 | } |
---|
| 38 | |
---|
[4aaeb66] | 39 | int getSamples(){ |
---|
[454b95c] | 40 | Serial.print("1"); |
---|
| 41 | Serial.print("\t"); |
---|
| 42 | Serial.print(TempSense.getTemp(CELSIUS)); |
---|
| 43 | Serial.println(); |
---|
| 44 | |
---|
[4aaeb66] | 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 | } |
---|
[454b95c] | 58 | } |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | void loop() { |
---|
| 62 | TempSense.overSample = true; |
---|
[4aaeb66] | 63 | if(getSamples()==1) { |
---|
| 64 | digitalWrite(outputLED, HIGH); |
---|
| 65 | } else { |
---|
| 66 | digitalWrite(outputLED, LOW); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | delay(100); |
---|
[454b95c] | 70 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.