Created
October 15, 2017 20:58
-
-
Save rubberduck203/8729509f77c3f8a07bee53b9a0aadcac to your computer and use it in GitHub Desktop.
Digital Thermometer Sketches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const uint8_t DATA = 7; | |
const uint8_t OUTPUT_ENABLE = 8; | |
const uint8_t LATCH = 9; | |
const uint8_t CLOCK = 10; | |
const uint8_t CLEAR = 11; | |
const uint8_t Zero = 0x3F; | |
const uint8_t One = 0x06; | |
const uint8_t Two = 0x5B; | |
const uint8_t Three = 0x4F; | |
const uint8_t Four = 0x66; | |
const uint8_t Five = 0x6D; | |
const uint8_t Six = 0x7D; | |
const uint8_t Seven = 0x07; | |
const uint8_t Eight = 0x7F; | |
const uint8_t Nine = 0x6F; | |
// Wire normally, but mount the display inverted so the decimal point is top left. | |
const uint8_t Celcius = 0x8F; | |
const uint8_t Farenheit = 0xCE; | |
const uint8_t Characters[] = {Zero,One,Two,Three,Four,Five,Six,Seven,Eight,Nine, Celcius, Farenheit}; | |
void setup() | |
{ | |
// Setup the pins connected to the shift register. | |
pinMode(DATA, OUTPUT); | |
pinMode(CLOCK, OUTPUT); | |
pinMode(LATCH, OUTPUT); | |
pinMode(OUTPUT_ENABLE, OUTPUT); | |
pinMode(CLEAR, OUTPUT); | |
//Hold OutputEnable low so we can display. | |
digitalWrite(OUTPUT_ENABLE, LOW); | |
//Hold Clear High so we don't reset as we're trying to display. | |
digitalWrite(CLEAR, HIGH); | |
//Initalize our clock low so we know it's inital state. | |
digitalWrite(CLOCK, LOW); | |
} | |
void loop() | |
{ | |
// put your main code here, to run repeatedly: | |
const int OneSec = 1000; | |
int8_t i; | |
for(i = 0; i < 12; i++) | |
{ | |
writeToDisplay(Characters[i]); | |
delay(OneSec); | |
} | |
/* Blast off countdown */ | |
// for(i = 9; i >= 0; i--) | |
// { | |
// writeToDisplay(Characters[i]); | |
// delay(OneSec); | |
// } | |
} | |
void writeToDisplay(uint8_t character) | |
{ | |
//Make sure latch is low so we display all segments at once. | |
digitalWrite(LATCH, LOW); | |
// circuit uses a common anode, so it pulls the segments to ground to activate; i.e. active LOW | |
// Because it's easier to think of 1 as on, NOT the bits before writing them. | |
shiftOut(DATA, CLOCK, MSBFIRST, ~character); | |
digitalWrite(LATCH, HIGH); //send it | |
digitalWrite(LATCH, LOW); //reset the latch; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const uint8_t CF_SWITCH = 2; | |
const uint8_t DATA = 7; | |
const uint8_t OUTPUT_ENABLE = 8; | |
const uint8_t LATCH = 9; | |
const uint8_t CLOCK = 10; | |
const uint8_t CLEAR = 11; | |
typedef uint8_t displayChar_t; | |
const displayChar_t Celcius = 0x8F; | |
const displayChar_t Farenheit = 0xCE; | |
void setup() { | |
//Setup switch input for ºC/ºF | |
pinMode(CF_SWITCH, INPUT_PULLUP); | |
// Setup the pins connected to the shift register. | |
pinMode(DATA, OUTPUT); | |
pinMode(CLOCK, OUTPUT); | |
pinMode(LATCH, OUTPUT); | |
pinMode(OUTPUT_ENABLE, OUTPUT); | |
pinMode(CLEAR, OUTPUT); | |
//Hold OutputEnable low so we can display. | |
digitalWrite(OUTPUT_ENABLE, LOW); | |
//Hold Clear High so we don't reset as we're trying to display. | |
digitalWrite(CLEAR, HIGH); | |
//Initalize our clock low so we know it's inital state. | |
digitalWrite(CLOCK, LOW); | |
} | |
void loop() { | |
int state = digitalRead(CF_SWITCH); | |
displayChar_t displayChar = (HIGH == state) ? Celcius : Farenheit; | |
//Make sure latch is low so we display all segments at once. | |
digitalWrite(LATCH, LOW); | |
// circuit uses a common anode, so it pulls the segments to ground to activate; i.e. active LOW | |
// Because it's easier to think of 1 as on, NOT the bits before writing them. | |
shiftOut(DATA, CLOCK, MSBFIRST, ~displayChar); | |
digitalWrite(LATCH, HIGH); //send it | |
digitalWrite(LATCH, LOW); //reset the latch; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment