// time, temperature, pressure, voltage display // eventually display to video with MAX7456 // temp/pressure protoshield with: // DS1631 I2C temp sensor // MPXAZ6115 pressure sensor // MCP3202 SPI dual 12 bit ADC // RTC shield with battery backed DS1307 // video overlay shield with MAX7456 // kg4wsv at or near gmail #include #include #include #include #include #include "MAX7456.h" MAX7456 osd; #define DS1631_ADDRESS 0x48 #define DATAFLASH_CS 8 // print prompts and messages from program flash to save SRAM void print_prompt_P(const char *data) { while (pgm_read_byte(data) != 0x00) Serial.print(pgm_read_byte(data++)); } int rtc[7]; // MCP3202 2 channel ADC // 3202 is different software-wise from 3204/3208 (which are identical) #define MOSI 11 #define MISO 12 #define SPICLOCK 13 #define SLAVE_SELECT_ADC1 4 int read_adc(byte cs, byte channel) { int adcvalue = 0; // byte commandbits = B11000000; //command bits - start, mode, chn (3), dont care (3) byte commandbits = B11010000; //command bits - start, mode, chn, MSBF //allow channel selection // commandbits|=((channel-1)<<3); commandbits|=(channel<<5); digitalWrite(cs, LOW); //Select adc // setup bits to be written // for (int i=7; i>=3; i--){ for (int i=7; i>=4; i--){ digitalWrite(MOSI,commandbits&1<=0; i--){ adcvalue+=digitalRead(MISO)<= 100) { temp_str[i++] = temp / 100 + '0'; temp = temp % 100; } if (temp >= 10) { temp_str[i++] = temp / 10 + '0'; temp %= 10; } temp_str[i++] = temp % 10 + '0'; temp_str[i++] = '.'; frac = 100 * (frac & 0xF0 )/ 256; temp_str[i++] = frac / 10 + '0'; temp_str[i++] = frac % 10 + '0'; temp_str[i++] = 'C'; temp_str[i++] = '\0'; return temp_str; } static char * time_string() { static char time_str[] = "00:00:00"; RTC.get(rtc,true); time_str[0] = rtc[2] / 10 + '0'; time_str[1] = rtc[2] % 10 + '0'; time_str[3] = rtc[1] / 10 + '0'; time_str[4] = rtc[1] % 10 + '0'; time_str[6] = rtc[0] / 10 + '0'; time_str[7] = rtc[0] % 10 + '0'; return time_str; } static char * date_string() { // US format static char date_str[] = "00/00/0000"; RTC.get(rtc,true); date_str[0] = rtc[4] / 10 + '0'; date_str[1] = rtc[4] % 10 + '0'; date_str[3] = rtc[5] / 10 + '0'; date_str[4] = rtc[5] % 10 + '0'; date_str[6] = rtc[6] / 1000 + '0'; date_str[7] = rtc[6] % 1000 / 100 + '0'; date_str[8] = rtc[6] % 100 / 10 + '0'; date_str[9] = rtc[6] % 1000 + '0'; return date_str; }