#include #include int PIN = 10 ; //pin at which interrupt is to be generated(pin connected to switch which when pressed will show temp on oscilloscope) int thermistorpin=A0; // which analog pin to connect int thermistornominal=150; // resistance at 25 degrees C int temperaturenominal=25; // temp. for nominal resistance (almost always 25 C) int numsamples =100; // how many samples to take and average, more takes longer // but is more 'smooth' int bcoefficient=3950; // The beta coefficient of the thermistor (usually 3000-4000) int seriesresistor=10000; // the value of the 'other' resistor int k; int t1,t2; //2 digits of temp int samples[100]; //no. of samples to be taken by A0 int dacx[]= { 9,8,7,6,5,4,3,2};//pins where 1st dac is connected int dacy[]= { 19,18,17,16,15,13,12,11}; //pins where 2nd dac is connected int sec=90; //controls second hand(90 is angle at 12 o'clock) int mint=90; //controls min hand int hour=120; //controls hour hand float mincos=0; //generates the value for sine and cos value for the end point of min hand float minsin=1; float hourcos=-0.866; //generates the value for sine and cos value for the end point of hour hand float hoursin=0.5; //ponits (bit values) for sine and cos waves unsigned char sinx[]= { 127,130,133,136,139,142,145,148,151,154,157,160,164,166,169,172,175,178,181,184,187,189,192,195, 197,200,202,205,207,210,212,214,217,219,221,223,225,227,229,231,232,234,236,237,239,240,242, 243,244,245,246,247,248,249, 250,251,251,252,252,253,253,253,253,253,254,253,253,253,253,252,252,251, 251,250,249,249,248,247,246,245,243,242,241,239,238,236,235,233,231,230, 228,226,224,222, 220,218, 215,213,211,209,206,204,201,199,196,193,191,188,185,182,180,177,174,171,168,165,162,159,156,153, 150,147,144,141,137,134,131,128,125,122,119,116,112,109,106,103,100,97,94,91,88,85,82, 79,76, 73,71,68,65,62,60,57,54,52,49,47,44,42,40,38,35,33,31,29,27,25,23,22,20,18,17,15,14, 12,11,10,8,7,6,5,4,4,3,2,2,1,1,0,0,0,0,0,0,0,0,0,0,1,1,2,2,3,4,5,6,7,8,9,10,11,13,14,16,17,19,21,22, 24, 26,28,30,32,34,36,39,41,43,46,48,51,53,56,58,61,64,66,69,72,75,78,81,84,87,89,93,96, 99,102,105,108,111,114,117,120,123,127 }; unsigned char cosx[]= { 254,253,253,253,253,252,252,251, 251,250,249,249,248,247,246,245,243,242,241,239,238,236,235,233,231,230, 228,226,224,222,220,218, 215,213,211,209,206,204,201,199,196,193,191,188,185,182,180, 177,174,171,168,165,162,159,156,153, 150,147,144,141,137,134,131,128,125,122,119,116,112,109,106,103,100,97,94,91,88,85,82,79,76, 73,71,68,65,62,60,57,54,52,49,47,44,42,40,38,35,33,31,29,27, 25,23,22,20,18,17,15,14, 12,11,10,8,7,6,5,4,4,3,2,2,1,1,0,0,0,0,0,0,0,0,0,0,1,1,2,2,3,4,5,6,7,8,9,10,11,13,14,16,17,19,21,22,24, 26,28,30,32,34,36,39,41,43,46,48,51,53,56,58,61,64,66,69,72,75, 78,81,84,87,89,93,96, 99,102,105,108,111,114,117,120,123,127,130,133,136,139,142,145,148,151,154,157,160,164,166,169,172,175,178,181,184,187,189,192,195, 197,200,202,205,207,210,212,214,217, 219,221,223,225,227,229,231,232,234,236,237,239,240,242,243, 244,245,246,247,248,249, 250,251,251,252,252,253,253,253,253,253,254 }; //sine and cosine value of angle at which 12 strokes of clock float strokeSin[]= { .0000,.5000,.8666,1.000,.8666,.5000,.0000,-.5000,-.8666,-1.000,-.8666,-.5000 }; float strokeCos[]= { 1.000,.8666,.5000,.0000,-.5000,-.8666,-1.000,-.8666,-.5000,.0000,.5000,.8666 }; unsigned long changeTime;// store program running time void setup() { pinMode(PIN, INPUT); //set the 10th pin to input digitalWrite(PIN, HIGH); //use the internal pullup resistor PCintPort::attachInterrupt(PIN, swapMode,FALLING); for(int i=0;i<=7;i++) { pinMode(dacx[i],OUTPUT); //declare dac's as output pinMode(dacy[i],OUTPUT); } changeTime=millis(); displayclock(); //dispay "CLOCK BY" displayName(); } void loop() { minLine(127,127); //function to display minute hand hourLine(127,127); //function to display hour hand circle(); // function to make a circle strokes(); // function to add 12 stroke lines representing 12 hours in clock secLine(127,127,sec); if((millis()-changeTime)>114) { sec--; if(sec==0) sec=360; //0 or 360 is angle at number three on clock if(sec==90) updateMin(); //when 60 sec are completed min hand is moved by 1 place changeTime=millis(); } } // function to calculate and display temp. //is called when interrupt is generated void swapMode() { uint8_t i; float average; // take N samples in a row, with a slight delay for (i=0; i< numsamples; i++) { samples[i] = analogRead(thermistorpin); delay(10); } // average all the samples out average = 0; for (i=0; i< numsamples; i++) { average += samples[i]; } average /= numsamples; // convert the value to resistance average = 1023 / average - 1; average = seriesresistor / average; float steinhart; steinhart = average / thermistornominal; // (R/Ro) steinhart = log(steinhart); // ln(R/Ro) steinhart /= bcoefficient; // 1/B * ln(R/Ro) steinhart += 1.0 / (temperaturenominal + 273.15); // + (1/To) steinhart = 1.0 / steinhart; // Invert steinhart -= 273.15; // convert to C steinhart=round(steinhart); //gives us an whole number t1=steinhart/10; //generates number at tens place t2=(int)steinhart%10; //generates number at ones place for(int m=0;m<=100;m++) { //display the temp as for eg "35*C" font(t1,50); font(t2,100); degree(145); celcius(160); } sec-=19; } void updateMin() { mint=mint-6; if(mint==0) mint=360; mincos=cos(PI*mint/180); minsin=sin(PI*mint/180); if(mint==90) updateHour; //when 60 min are completed hour hand is moved by 1 place } void updateHour() { hour=hour-30; if(hour==0) hour=360; hourcos=cos(PI*hour/180); hoursin=sin(PI*hour/180); } void point(int x,int y) //plot a point on xy plane of oscilloscope { for(int j=0;j<=7;j++) { digitalWrite(dacx[j],(( x & 1<0)); } for(int j=0;j<=7;j++) { digitalWrite( dacy[j],(( y & 1<0)); } } void parallely(int a,int b,int c) //function to draw a line parallel to y axis(a is point constant on x axis and point on y axis varies from b to c) { for(k=b;k