#include <avr/eeprom.h>
#define COMMON_CATHODE // This device is common cathode
-#define HAVE_SHIFT_REGISTER 1 // We are using a shift register
// declare the digital pins for each segment led
#define SEG_A 6
#define SEG_DP 13
#define LED_PIN 13
-#define SHIFTREG_DATA 4 // DS pin
-#define SHIFTREG_CLOCK 3 // SHCP pin
-#define SHIFTREG_LATCH 2 // STCP pin
+#define MOC_PIN 8
+#define SHIFTREG_CLOCK 2 // SHCP (pin 11)
+#define SHIFTREG_LATCH 3 // STCP (pin 12)
+#define SHIFTREG_DATA 4 // DS (pin 14)
#define BUTTON_L 6 // left button
#define BUTTON_R 5 // right button
static void
set_segments(byte v)
{
-#if HAVE_SHIFT_REGISTER
digitalWrite(SHIFTREG_LATCH, LOW);
shiftOut(SHIFTREG_DATA, SHIFTREG_CLOCK, MSBFIRST, v);
digitalWrite(SHIFTREG_LATCH, HIGH);
-#else
- digitalWrite(SEG_G, (v & 0x40) ? SEG_ON : SEG_OFF);
- digitalWrite(SEG_F, (v & 0x20) ? SEG_ON : SEG_OFF);
- digitalWrite(SEG_E, (v & 0x10) ? SEG_ON : SEG_OFF);
- digitalWrite(SEG_D, (v & 0x08) ? SEG_ON : SEG_OFF);
- digitalWrite(SEG_C, (v & 0x04) ? SEG_ON : SEG_OFF);
- digitalWrite(SEG_B, (v & 0x02) ? SEG_ON : SEG_OFF);
- digitalWrite(SEG_A, (v & 0x01) ? SEG_ON : SEG_OFF);
-#endif
}
// Select one digit and display the value using the lookup table to
// select our digit and configure
digitalWrite(select[digit], LOW);
-#if HAVE_SHIFT_REGISTER
set_segments( Digits[num[digit] - 0x30] | ((digit == 1) ? 0x80 : 0) );
-#else
- set_segments(Digits[num[digit] - 0x30]);
- // set the decimal point on digit 2
- digitalWrite(SEG_DP, (digit == 1) ? SEG_ON : SEG_OFF);
-#endif
}
// Initialize timer2 as interrupt source
current_digit = (current_digit + 1) % 4;
++led_cnt;
if (led_cnt > 166) {
- PORTB ^= _BV(PB5);
+ //PORTB ^= _BV(PB5); // toggle pin 13
led_cnt = 0;
}
}
// Enable the internal 1.1V AREF (requires 10nF cap to GND)
analogReference(INTERNAL);
+ pinMode(LM35_PIN, INPUT);
-#if HAVE_SHIFT_REGISTER
pinMode(SHIFTREG_DATA, OUTPUT);
pinMode(SHIFTREG_LATCH, OUTPUT);
pinMode(SHIFTREG_CLOCK, OUTPUT);
pinMode(BUTTON_L, INPUT);
pinMode(BUTTON_R, INPUT);
+ pinMode(MOC_PIN, OUTPUT);
+ digitalWrite(MOC_PIN, HIGH);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
-#else
- pinMode(SEG_A, OUTPUT);
- pinMode(SEG_B, OUTPUT);
- pinMode(SEG_C, OUTPUT);
- pinMode(SEG_D, OUTPUT);
- pinMode(SEG_E, OUTPUT);
- pinMode(SEG_F, OUTPUT);
- pinMode(SEG_G, OUTPUT);
- pinMode(SEG_DP, OUTPUT);
-#endif
+
pinMode(SEL_1, OUTPUT);
pinMode(SEL_2, OUTPUT);
pinMode(SEL_3, OUTPUT);
Timer2Init();
}
+#define AREF 105L
+
static long getTemperature()
{
- long v;
+ long v,v1;
v = analogRead(LM35_PIN);
+ // v * REFERENCE) / NSTEPS
+ v1 = (v * AREF * 100L) / 1024L;
+ v = (v * 10000L) / 1024L;
+ Serial.print("[");
Serial.print(v);
- v = v * 10000L / 931L;
Serial.print(" ");
+ Serial.print(v1);
+ Serial.print("] ");
return v;
}
v += t[n];
}
v /= NUMSAMPLES;
+ // setting pin 8 low puts the MOC led _on_
+ if (v < target_temp) {
+ digitalWrite(MOC_PIN, LOW);
+ digitalWrite(LED_PIN, HIGH);
+ } else {
+ digitalWrite(MOC_PIN, HIGH);
+ digitalWrite(LED_PIN, LOW);
+ }
+ // pin 8 == PORTB pin 0: low for on
+ Serial.print((PORTB&1) ? "off " : "on ");
Serial.println(v);
setDisplay(v);
}