Açıklama
|
#include "SPI.h"#include "OneWire.h"#include "DallasTemperature.h"#define DS1307_ADDRESS 0x68#define ONE_WIRE_BUS 2#include "Wire.h"#include "max7219.h"#define LEFT 0#define RIGHT 1MAX7219 max7219;OneWire oneWire(ONE_WIRE_BUS);DallasTemperature sensors(&oneWire);#define DS1307_ADDRESS 0x68int a = 0;float temp = 0;void setup(){ Serial.begin(9600); max7219.Begin(); Wire.begin(); sensors.begin(); sensors.requestTemperatures(); temp = sensors.getTempCByIndex(0);}byte bcdToDec(byte val) {// Convert binary coded decimal to normal decimal numbers return ( (val/16*10) + (val%16) );}void printDate(){ // Reset the register pointer Wire.beginTransmission(DS1307_ADDRESS); byte zero = 0x00; Wire.write(zero); Wire.endTransmission(); Wire.requestFrom(DS1307_ADDRESS, 7); int second = bcdToDec(Wire.read()); int minute = bcdToDec(Wire.read()); int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday int monthDay = bcdToDec(Wire.read()); int month = bcdToDec(Wire.read()); int year = bcdToDec(Wire.read());char cstr[4]="";String str="";str = String(minute);str.toCharArray(cstr,4); max7219.Clear(); max7219.DisplayText(cstr, RIGHT); delay(1000);}void printTemp() { Wire.begin(); sensors.begin(); sensors.requestTemperatures(); temp = sensors.getTempCByIndex(0); Wire.end(); char a[5]=""; dtostrf(temp, 5, 2, a); char b[2]=" C"; char c[8]=""; strcat(c,a); strcat(c,b); max7219.Clear(); max7219.DisplayText(c, LEFT);}void loop() { printTemp(); delay(400);}
|
|