From: Pat Thoyts Date: Sun, 28 Apr 2013 14:36:20 +0000 (+0100) Subject: Removed the non-shiftreg code and added the MOC triac control output X-Git-Url: https://privyetmir.co.uk/gitweb.cgi?a=commitdiff_plain;h=42dc8223675ffd1eea55fb2cccf2e159b57e9891;p=arduino%2FPlateWarmer.git Removed the non-shiftreg code and added the MOC triac control output Signed-off-by: Pat Thoyts --- diff --git a/PlateWarmer.ino b/PlateWarmer.ino index 22a45ab..a43cb1e 100644 --- a/PlateWarmer.ino +++ b/PlateWarmer.ino @@ -17,7 +17,6 @@ #include #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 @@ -30,9 +29,10 @@ #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 @@ -98,19 +98,9 @@ static void Serial_print(PGM_P s) 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 @@ -134,13 +124,7 @@ display(int digit, const char *num) // 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 @@ -175,7 +159,7 @@ ISR(TIMER2_OVF_vect) current_digit = (current_digit + 1) % 4; ++led_cnt; if (led_cnt > 166) { - PORTB ^= _BV(PB5); + //PORTB ^= _BV(PB5); // toggle pin 13 led_cnt = 0; } } @@ -223,25 +207,18 @@ setup() // 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); @@ -257,13 +234,20 @@ setup() 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; } @@ -354,6 +338,16 @@ loop() 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); }