Skip to content

Instantly share code, notes, and snippets.

@dansku
Created May 31, 2013 05:59
Show Gist options
  • Save dansku/5683157 to your computer and use it in GitHub Desktop.
Save dansku/5683157 to your computer and use it in GitHub Desktop.
Adding temperature to Dotklok
// temperature()
// Temperature Sensor + Clock - by Daniel Spillere Andrade - www.DanielAndrade.net
// Should Change the Temperature Only when minutes change, to prevent floating on temperature
// Based on http://www.danielandrade.net/2008/07/05/temperature-sensor-arduino/ - Daniel Spillere Andrade - daniel [a] danielandrade.net
void temperature(){
ht1632_clear();
plot(0,0,1); plot(0,15,1); plot(23,15,1); plot(23,0,1);
//Draw Dots and Temperature
plot(7,3,1);
plot(7,5,1);
plot(16,3,1);
plot(16,5,1);
plot(13,9,1);
plot(13,10,1);
plot(14,9,1);
plot(14,10,1);
// Drawing the 'C', it's ugly I know :)
for(int i=16;i<19;i++){
for(int j=9;j<14;j++){
if(j==9 || j==13) { plot (i,j,1);}
else { plot(16,j,1); }
}
}
int temppin = 3; // Define LM35 PIN
int tempval; // Temperature Read Variable
tempval = ( 5.0 * analogRead(temppin) * 100.0) / 1024.0; //Makes the first read
/* TIME LOOP */
do{
time_now = RTC.now();
if( ( time_now.minute() != time_prev.minute() ) ){
if( !power_up && midnight_random() ) return;
tempval = 0;
for(int i=0;i< =9;i++){
tempval = tempval + (( 5.0 * analogRead(temppin) * 100.0) / 1024.0); // Reads the Variable and converts to Celsius
delay(100); // tempf = (tempval * 9)/ 5 + 32; to converts to fahrenheit
}
tempval = tempval/10;
}
// Here starts the code. :)
// Draw Temperature, only when minute changes!
putchar_3x5(5,9,(tempval%100)/10);
putchar_3x5(9,9,tempval%10);
//Draw Time
putchar_3x5(0,2,(time_now.hour()%100)/10);
putchar_3x5(3,2,time_now.hour()%10);
putchar_3x5(9,2,time_now.minute()/10);
putchar_3x5(12,2,time_now.minute()%10);
putchar_3x5(18,2,time_now.second()/10);
putchar_3x5(21,2,time_now.second()%10);
time_prev = time_now;
/* CHECK BUTTONS, return if necessary */
if( change_animation() ) return;
while( PAUSE && b5.isPressed( )); // pause mode for photos
} while(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment