|
|

楼主 |
发表于 2013-10-1 01:35:17
|
显示全部楼层
- #define LCD_CS A3
- #define LCD_CD A2
- #define LCD_WR A1
- #define LCD_RD A0
- // you can also just connect RESET to the arduino RESET pin
- #define LCD_RESET -1
- //Duemilanove/Diecimila/UNO/etc ('168 and '328 chips) microcontoller:
- // Color definitions
- #define BLACK 0x0000
- #define BLUE 0x001F
- #define RED 0xF800
- #define GREEN 0x07E0
- #define CYAN 0x07FF
- #define MAGENTA 0xF81F
- #define YELLOW 0xFFE0
- #define WHITE 0xFFFF
- #define DS1307COLOR 0x07E0
- #define BACKCOLOR 0x0000
- #define BMP085COLOR 0x07FF
- #define FRAMECOLOR 0x07FF
- #include "TFTLCD.h"
- TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
- ///////////////////////////////////////////////////////////////
- #include <Wire.h>
- #include <RTClib.h>
- RTC_DS1307 RTC; // Tiny RTC Modul
- const char *DOW[8] = {
- "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT","SUN"};
- /////////////////////////////////////////////////////////////
- #include <Adafruit_BMP085.h>
- Adafruit_BMP085 bmp;
- ////////////////////////////////////////////
- unsigned char frequencyH = 0;
- unsigned char frequencyL = 0;
- unsigned int frequencyB;
- double frequency = 0;
- //////////////////////////////////////////
- #include "TouchScreen.h"
- #define YP A1 // must be an analog pin, use "An" notation!
- #define XM A2 // must be an analog pin, use "An" notation!
- #define YM 7 // can be a digital pin
- #define XP 6 // can be a digital pin
- #define TS_MINX 150
- #define TS_MINY 120
- #define TS_MAXX 920
- #define TS_MAXY 940
- // For better pressure precision, we need to know the resistance
- // between X+ and X- Use any multimeter to read it
- // For the one we're using, its 300 ohms across the X plate
- TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
- #define MINPRESSURE 10
- #define MAXPRESSURE 1000
- //////////////////////////////////
- char temp_str[12];
- int temp_sec=0;
- void setup(void) {
- Wire.begin();
- RTC.begin();
- bmp.begin();
- Serial.begin(9600);
- //Serial.println("8 Bit LCD test!");
- tft.reset();
- tft.initDisplay();
- tft.fillScreen(BLUE);
- frequency = 92.3; //starting frequency
- setFrequency();
- tft.setTextColor(DS1307COLOR);
- tft.setTextSize(2);
- tft.setCursor(5, 15);
- DateTime now=RTC.now();
- temp_sec=now.second();
- show_date(now.dayOfWeek(),now.day(),now.month(),now.year());
- show_hour(now.hour());
- show_minute(now.minute());
- show_bmp085();
- }
- void loop(void) {
- digitalWrite(13, HIGH);
- Point p = ts.getPoint();
- digitalWrite(13, LOW);
- pinMode(XM, OUTPUT);
- pinMode(YP, OUTPUT);
- p.x = map(p.x, TS_MAXX, TS_MINX, tft.width(), 0);
- p.y = map(p.y, TS_MAXY, TS_MINY, tft.height(), 0);
- //tft.setTextWrap(false);
- DateTime now=RTC.now();
- if (temp_sec!=now.second()){
- temp_sec=now.second();
- //dot_color=!dot_color;
- if (temp_sec%2==0) {
- tft.fillRect(80,70,9,9,GREEN);
- tft.fillRect(80,90,9,9,GREEN);
- Serial.print(temp_sec);
- }
- else{
- tft.fillRect(80,70,9,9,WHITE);
- tft.fillRect(80,90,9,9,WHITE);
- Serial.print(temp_sec);
- }
- tft.setCursor(5,110);
- tft.setTextColor(WHITE);
- tft.fillRect(5,110,50,50,BLACK);
- tft.print(temp_sec);
- Serial.println(temp_sec);
- if (now.second()==0) {
- show_minute(now.minute());
- if (now.minute()==0){
- show_hour(now.hour());
- if (now.hour()==0) show_date(now.dayOfWeek(),now.day(),now.month(),now.year());
- }
- }
- if (now.second()==0 || now.second()==30) show_bmp085();
- }
- if (p.z > 5){
- Serial.print(p.x);
- Serial.print("-");
- Serial.print(p.y);
- Serial.print("-");
- Serial.println(p.z);
- }
- }
- void setFrequency()
- {
- frequencyB = 4 * (frequency * 1000000 + 225000) / 32768;
- frequencyH = frequencyB >> 8;
- frequencyL = frequencyB & 0XFF;
- delay(100);
- Wire.beginTransmission(0x60);
- Wire.write(frequencyH);
- Wire.write(frequencyL);
- Wire.write(0xB0);
- Wire.write(0x10);
- Wire.write((byte)0x00);
- Wire.endTransmission();
- delay(100);
- }
- // Draw a red frame while a button is touched
- void waitForIt(int x1, int y1, int x2, int y2)
- {
- //.setColor(255, 0, 0);
- //myGLCD.drawRoundRect (x1, y1, x2, y2);
- //while (myTouch.dataAvailable())
- // myTouch.read();
- //myGLCD.setColor(255, 255, 255);
- //myGLCD.drawRoundRect (x1, y1, x2, y2);
- //touch_read();
- //tft.drawRect(x1,y1,x2,y2,FRAMECOLOR);
- //while (p.z>10) touch_read();
- //tft.drawRect(x1,y1,x2,y2,BACKCOLOR);
- }
- void show_date(int w,int d,int m, int y)
- {
- tft.setTextColor(DS1307COLOR);
- tft.fillRect(5,5,240,30,BACKCOLOR);
- tft.setTextSize(2);
- tft.setCursor(5, 15);
- tft.print(DOW[w]);
- sprintf(temp_str, "%02d-%02d-%04d", d, m, y);
- tft.setCursor(60, 10);
- tft.setTextSize(3);
- tft.print(temp_str);
- }
- void show_hour(int h)
- {
- tft.setTextColor(DS1307COLOR);
- tft.fillRect(5,60,70,45,BACKCOLOR);
- tft.setTextSize(6);
- tft.setCursor(5, 60);
- sprintf(temp_str,"%02d",h);
- tft.print(temp_str);
- }
- void show_minute(int m)
- {
- tft.setTextColor(DS1307COLOR);
- tft.fillRect(95,60,70,45,BACKCOLOR);
- tft.setTextSize(6);
- tft.setCursor(95, 60);
- sprintf(temp_str,"%02d",m);
- tft.print(temp_str);
- }
- void show_bmp085()
- {
- tft.setTextColor(BMP085COLOR);
- tft.fillRect(170,50,70,55,BACKCOLOR);
- tft.setTextSize(2);
- tft.setCursor(170, 50);
- tft.print(bmp.readTemperature());
- tft.setCursor(170, 70);
- tft.print(bmp.readAltitude());
- tft.setCursor(170, 90);
- tft.print(bmp.readPressure());
- }
复制代码 |
|