 | Код: // INCLUDES #include <DallasTemperature.h> #include <OneWire.h> #define ONE_WIRE_BUS 5 OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire);
#include <SoftwareSerial.h> #include <TinyGPS.h> #include <SPI.h> #include "TPIC6B595.h" #include <TimeLib.h> #define RXPIN 4 #define TXPIN 3 #define GPSBAUD 9600
TinyGPS gps; SoftwareSerial uart_gps(RXPIN, TXPIN);
//Pin Assignments (You should change these) const int clockPin = 9; //Connected to TPIC pin 13: SRCLK (aka Clock) const int latchPin = 10; //Connected to TPIC pin 12: RCLK (aka Latch/load/CS/SS...) const int dataPin = 12; //Connected to TPIC pin 3: SER (aka MOSI)
byte IC1[] = { B11111100, B01100000, B11011010, B11110010, B01100110, B10110110, B10111110, B11100000, B11111110, B11110110 };
// VARIABLES int seconds; int timeoffset = +3; // User must change the one to an appropiate number. I am one hour after GMT. int temps; void setup() { sensors.begin();
uart_gps.begin(GPSBAUD); // Start the GPS receiver UART pinMode(clockPin, OUTPUT); pinMode(latchPin, OUTPUT); pinMode(dataPin, OUTPUT); delay(1000); Serial.begin(9600); }
void loop() {
if (uart_gps.available()) { int c = uart_gps.read(); if (gps.encode(c)) { getgps(gps); } } else { temp(); } }
void getgps(TinyGPS &gps) //void loop() { int year; float latitude, longitude; byte month, day, hour, minute, second, hundredths; int deschas, edchas, chas1, chas2; int desmin, edmin, minut1, minut2; // gps.f_get_position(&latitude, &longitude); gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths); //hour = 15; hour = hour + timeoffset; chas1 = hour % 10; chas2 = hour / 10; edchas = IC1[chas1]; deschas = IC1[chas2];
//minute = 32; minut1 = minute % 10; minut2 = minute / 10; edmin = IC1[minut1]; desmin = IC1[minut2];
digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, LSBFIRST, edmin); shiftOut(dataPin, clockPin, LSBFIRST, desmin); shiftOut(dataPin, clockPin, LSBFIRST, edchas); shiftOut(dataPin, clockPin, LSBFIRST, deschas); digitalWrite(latchPin, HIGH); Serial.print("hour = "); Serial.println(hour); Serial.print("min = "); Serial.println(minute); delay(5000);
int temp, destemp, edtemp, temp1, temp2; sensors.requestTemperatures(); // Send the command to get temperatures temp = sensors.getTempCByIndex(0); // temp = -5; if (temp < 0) { temp = abs(temp); temp1 = temp % 10; temp2 = temp / 10; edtemp = IC1[temp1]; destemp = IC1[temp2]; digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, LSBFIRST, B11000110); shiftOut(dataPin, clockPin, LSBFIRST, edtemp); shiftOut(dataPin, clockPin, LSBFIRST, destemp); shiftOut(dataPin, clockPin, LSBFIRST, B00000010); digitalWrite(latchPin, HIGH); } else { temp1 = temp % 10; temp2 = temp / 10; edtemp = IC1[temp1]; destemp = IC1[temp2]; digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, LSBFIRST, B10011100); shiftOut(dataPin, clockPin, LSBFIRST, B11000110); shiftOut(dataPin, clockPin, LSBFIRST, edtemp); shiftOut(dataPin, clockPin, LSBFIRST, destemp); digitalWrite(latchPin, HIGH); } Serial.print( " temp = "); Serial.println(temp); delay(5000); }
void temp() {
int temp, destemp, edtemp, temp1, temp2; sensors.requestTemperatures(); // Send the command to get temperatures temp = sensors.getTempCByIndex(0); // temp = -5; if (temp < 0) { temp = abs(temp); temp1 = temp % 10; temp2 = temp / 10; edtemp = IC1[temp1]; destemp = IC1[temp2]; digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, LSBFIRST, B11000110); shiftOut(dataPin, clockPin, LSBFIRST, edtemp); shiftOut(dataPin, clockPin, LSBFIRST, destemp); shiftOut(dataPin, clockPin, LSBFIRST, B00000010); digitalWrite(latchPin, HIGH); } else { temp1 = temp % 10; temp2 = temp / 10; edtemp = IC1[temp1]; destemp = IC1[temp2]; digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, LSBFIRST, B10011100); shiftOut(dataPin, clockPin, LSBFIRST, B11000110); shiftOut(dataPin, clockPin, LSBFIRST, edtemp); shiftOut(dataPin, clockPin, LSBFIRST, destemp); digitalWrite(latchPin, HIGH); }
Serial.println( " no gps "); Serial.print(" temp = "); Serial.println(temp); delay(2000); }
|  |