Ср сен 09, 2020 16:52:40
/*
#include <Wire.h> // i2c wire libraries for RTC
#include "RTClib.h" // RTC libraries
const int g_pinData = 10; // SI (Pin 14 on 74595) Red wire
const int g_pinCommLatch = 11; // RCK (Pin 12 on 74595) White wire
const int g_pinClock = 12; // SCK (Pin 11 on 74595) Green wire
const int ledPin = 13; // for blinking every 1/2 seconds
int temp = 0;
int humid = 0;
int volt = 0;
RTC_DS1307 RTC; // define RTC variables
byte g_digits [10]; // Definitions of the 7-bit values for displaying digits
int g_numberToDisplay = 0; // default number being displayed, 0
const int g_registers = 4; // Number of shift registers in use, 4
byte g_registerArray [g_registers]; // Array of numbers to pass to shift registers
// Begin setup() functions //
float get3231Temp(){
byte tMSB, tLSB;
float temp3231;
Wire.beginTransmission(0x68);
Wire.write(0x11);
Wire.endTransmission();
Wire.requestFrom(0x68, 2);
if(Wire.available()) {
tMSB = Wire.read(); //2's complement int portion
tLSB = Wire.read(); //fraction portion
temp3231 = (tMSB & B01111111); //do 2's math on Tmsb
temp3231 += ( (tLSB >> 6) * 0.25 ); //only care about bits 7 & 8
}
else {
//oh noes, no data!
}
return temp3231;
}
void setup()
{
// I2C RTC Setup
Wire.begin();
RTC.begin();
/* Only set the time on compile if the RTC is not running...
This is used to set the current time from the computer clock
if ( !RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
*/
pinMode (g_pinCommLatch, OUTPUT); // define 74595 pins as output
pinMode (g_pinClock, OUTPUT); // define 74595 pins as output
pinMode (g_pinData, OUTPUT); // define 74595 pins as output
pinMode (ledPin, OUTPUT); // define LED pins as output
Serial.begin (9600); // optional, turn on serial monitoring for debugging
// Setup 7 segment display for number 0 to 9 and other characters
// a - top bar
// b - top right
// c - bottom right
// d - bottom bar
// e - bottom left
// f - top right
// g - middle bar
int a = 1, b = 2, c = 4, d = 8, e = 16, f = 32, g = 64;
g_digits [0] = 8 + 4 + 2 + 64 + 32 + 1;
g_digits [1] = 4 + 2;
g_digits [2] = 8 + 4 + 16 + 32 + 64;
g_digits [3] = 8 + 4 + 16 + 2 + 64;
g_digits [4] = 1 + 16 + 4 + 2;
g_digits [5] = 8 + 1 + 16 + 2 + 64;
g_digits [6] = 8 + 1 + 16 + 2 + 64 + 32;
g_digits [7] = 8 + 4 + 2;
g_digits [8] = 8 + 4 + 2 + 64 + 32 + 1 + 16;
g_digits [9] = 8 + 4 + 2 + 1 + 16 + 64;
g_digits [90] = a + d + e + c; // Degree dot
g_digits [91] = a +d+f+g; // Capital C
g_digits [92] = e + g; // r, 80
g_digits [93] = f + e + g + c; // h, 116
g_digits [94] = f + e + g + c;
g_digits [99] = 0;
// 7-segment testing... blink 4 times
for (int i=0;i<5;i++) {
g_registerArray [0] = g_digits [8];
g_registerArray [1] = g_digits [8];
g_registerArray [2] = g_digits [8];
g_registerArray [3] = g_digits [8];
sendSerialData (g_registers, g_registerArray);
delay(300);
g_registerArray [0] = g_digits [99];
g_registerArray [1] = g_digits [99];
g_registerArray [2] = g_digits [99];
g_registerArray [3] = g_digits [99];
sendSerialData (g_registers, g_registerArray);
delay(300);
}
} // End of setup() //
// Простая функция для отправки последовательных данных в один или несколько сдвиговых регистров путем итерации назад по массиву.
// Хотя g_registers существует, они могут использоваться не все, следовательно, входной параметр.
void sendSerialData (
byte registerCount, // Сколько сдвиговых регистров?
byte *pValueArray) // Массив байтов с LSByte в массиве [0]
{
// Сигнал 595s для чтения данных
digitalWrite (g_pinCommLatch, LOW);
for (byte reg = registerCount; reg > 0; reg--)
{
byte value = pValueArray [reg - 1];
for (byte bitMask = 128; bitMask > 0; bitMask >>= 1)
{
digitalWrite (g_pinClock, LOW);
digitalWrite (g_pinData, value & bitMask ? HIGH : LOW);
digitalWrite (g_pinClock, HIGH);
}
}
// Сигнал 595s, что я закончил посылать
digitalWrite (g_pinCommLatch, HIGH);
} // отправка последовательных данных
// ==== Main loop() =====
void loop()
{
byte temp = get3231Temp();
int hour,minute,sec,disp = 0;
DateTime now = RTC.now(); // Получить текущее время и дату
hour = now.hour(); // break down time to hour
minute = now.minute(); // break down time to minute
sec = now.second(); // break down time to second
// Push the hour 2 digits to the left by multiplying 100
disp = (hour * 100) + minute;
g_numberToDisplay = disp;
{
if (g_numberToDisplay < 10)
{
g_registerArray [0] = g_digits [0];
g_registerArray [1] = g_digits [0];
g_registerArray [2] = g_digits [0];
g_registerArray [3] = g_digits [g_numberToDisplay];
}
else if (g_numberToDisplay < 100)
{
g_registerArray [0] = g_digits [0];
g_registerArray [1] = g_digits [0];
g_registerArray [2] = g_digits [g_numberToDisplay / 10];
g_registerArray [3] = g_digits [g_numberToDisplay % 10];
}
else if (g_numberToDisplay < 1000)
{
g_registerArray [0] = g_digits [0];
g_registerArray [1] = g_digits [g_numberToDisplay / 100];
g_registerArray [2] = g_digits [(g_numberToDisplay % 100) / 10];
g_registerArray [3] = g_digits [g_numberToDisplay % 10];
}
else
{
g_registerArray [0] = g_digits [g_numberToDisplay / 1000];
g_registerArray [1] = g_digits [(g_numberToDisplay % 1000) / 100];
g_registerArray [2] = g_digits [(g_numberToDisplay % 100) / 10];
g_registerArray [3] = g_digits [g_numberToDisplay % 10];
sendSerialData (g_registers, g_registerArray);
// Blink the LED connected to pin 13
digitalWrite(ledPin,HIGH);
delay(1000);
digitalWrite(ledPin,LOW);
delay(1000);
digitalWrite(ledPin,HIGH);
delay(1000);
digitalWrite(ledPin,LOW);
delay(1000);
digitalWrite(ledPin,HIGH);
delay(1000);
digitalWrite(ledPin,LOW);
delay(1000);
digitalWrite(ledPin,HIGH);
delay(1000);
digitalWrite(ledPin,LOW);
delay(1000);
digitalWrite(ledPin,HIGH);
delay(1000);
digitalWrite(ledPin,LOW);
delay(1000);
}
byte temp = get3231Temp();
}
g_registerArray [0] = g_digits [temp / 10];
g_registerArray [1] = g_digits [temp % 10];
g_registerArray [2] = g_digits [90]; // Degree symbol
g_registerArray [3] = g_digits [91]; // C
sendSerialData (g_registers, g_registerArray);
delay(3000);
}
Ср сен 09, 2020 18:10:03
disp = (hour * 100) + minute;
g_numberToDisplay = disp;
{ // вот это что за фигурная скобка? Такая же и внизу кода.
if (g_numberToDisplay < 10)
{
Чт сен 10, 2020 16:00:00
/*
Red = Ard Pin 10
White = Ard Pin 11
Green = Ard Pin 12
DHT11() is disabled
Version 1.2 with DHT11 RH, DS18B20 & Temp & secret voltmeter
Version 1.3 with 7-segment testing, blink 5 times
Original sketch from Paul Electronics 7-segment shift register posting
RTC libraries from http://jeelabs.net/projects/cafe/wiki/RTClib
Setting realtime clock on-compile was from Ladyada.net
Pin assignment on the 74595 to 7-segment common cathode as follows :-
QA - a
QB - b
QC - c
QD - d
QE - e
QF - f
QG - g
pin 3 & 8 are common cathode
resistors used is 220R
Stanley Seow
stanleyseow@gmail.com
*/
#include <Wire.h> // i2c wire libraries for RTC
#include "RTClib.h" // RTC libraries
const int g_pinData = 10; // SI (Pin 14 on 74595) Red wire
const int g_pinCommLatch = 11; // RCK (Pin 12 on 74595) White wire
const int g_pinClock = 12; // SCK (Pin 11 on 74595) Green wire
const int ledPin = 13; // for blinking every 1/2 seconds
int temp = 0;
int humid = 0;
int volt = 0;
RTC_DS1307 RTC; // define RTC variables
byte g_digits [10]; // Definitions of the 7-bit values for displaying digits
int g_numberToDisplay = 0; // default number being displayed, 0
const int g_registers = 4; // Number of shift registers in use, 4
byte g_registerArray [g_registers]; // Array of numbers to pass to shift registers
// Begin setup() functions //
float get3231Temp(){
byte tMSB, tLSB;
float temp3231;
Wire.beginTransmission(0x68);
Wire.write(0x11);
Wire.endTransmission();
Wire.requestFrom(0x68, 2);
if(Wire.available()) {
tMSB = Wire.read(); //2's complement int portion
tLSB = Wire.read(); //fraction portion
temp3231 = (tMSB & B01111111); //do 2's math on Tmsb
temp3231 += ( (tLSB >> 6) * 0.25 ); //only care about bits 7 & 8
}
else {
//oh noes, no data!
}
return temp3231;
}
void setup()
{
// I2C RTC Setup
Wire.begin();
RTC.begin();
/* Only set the time on compile if the RTC is not running...
This is used to set the current time from the computer clock
if ( !RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
*/
pinMode (g_pinCommLatch, OUTPUT); // define 74595 pins as output
pinMode (g_pinClock, OUTPUT); // define 74595 pins as output
pinMode (g_pinData, OUTPUT); // define 74595 pins as output
pinMode (ledPin, OUTPUT); // define LED pins as output
Serial.begin (9600); // optional, turn on serial monitoring for debugging
// Setup 7 segment display for number 0 to 9 and other characters
// a - top bar
// b - top right
// c - bottom right
// d - bottom bar
// e - bottom left
// f - top right
// g - middle bar
int a = 1, b = 2, c = 4, d = 8, e = 16, f = 32, g = 64;
g_digits [0] = 8 + 4 + 2 + 64 + 32 + 1;
g_digits [1] = 4 + 2;
g_digits [2] = 8 + 4 + 16 + 32 + 64;
g_digits [3] = 8 + 4 + 16 + 2 + 64;
g_digits [4] = 1 + 16 + 4 + 2;
g_digits [5] = 8 + 1 + 16 + 2 + 64;
g_digits [6] = 8 + 1 + 16 + 2 + 64 + 32;
g_digits [7] = 8 + 4 + 2;
g_digits [8] = 8 + 4 + 2 + 64 + 32 + 1 + 16;
g_digits [9] = 8 + 4 + 2 + 1 + 16 + 64;
g_digits [90] = a + d + e + c; // Degree dot
g_digits [91] = a +d+f+g; // Capital C
g_digits [92] = e + g; // r, 80
g_digits [93] = f + e + g + c; // h, 116
g_digits [94] = f + e + g + c;
g_digits [99] = 0;
// 7-segment testing... blink 4 times
for (int i=0;i<5;i++) {
g_registerArray [0] = g_digits [8];
g_registerArray [1] = g_digits [8];
g_registerArray [2] = g_digits [8];
g_registerArray [3] = g_digits [8];
sendSerialData (g_registers, g_registerArray);
delay(300);
g_registerArray [0] = g_digits [99];
g_registerArray [1] = g_digits [99];
g_registerArray [2] = g_digits [99];
g_registerArray [3] = g_digits [99];
sendSerialData (g_registers, g_registerArray);
delay(300);
}
} // End of setup() //
// Простая функция для отправки последовательных данных в один или несколько сдвиговых регистров путем итерации назад по массиву.
// Хотя g_registers существует, они могут использоваться не все, следовательно, входной параметр.
void sendSerialData (
byte registerCount, // Сколько сдвиговых регистров?
byte *pValueArray) // Массив байтов с LSByte в массиве [0]
{
// Сигнал 595s для чтения данных
digitalWrite (g_pinCommLatch, LOW);
for (byte reg = registerCount; reg > 0; reg--)
{
byte value = pValueArray [reg - 1];
for (byte bitMask = 128; bitMask > 0; bitMask >>= 1)
{
digitalWrite (g_pinClock, LOW);
digitalWrite (g_pinData, value & bitMask ? HIGH : LOW);
digitalWrite (g_pinClock, HIGH);
}
}
// Сигнал 595s, что я закончил посылать
digitalWrite (g_pinCommLatch, HIGH);
} // отправка последовательных данных
// ==== Main loop() =====
void loop()
{
byte temp = get3231Temp();
int hour,minute,sec,disp = 0;
DateTime now = RTC.now(); // Получить текущее время и дату
hour = now.hour(); // break down time to hour
minute = now.minute(); // break down time to minute
sec = now.second(); // break down time to second
/* Serial output debugging for the date & time
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
*/
Serial.print(hour);
Serial.print(':');
Serial.print(minute);
Serial.print(':');
Serial.print(sec);
Serial.println();
Serial.print("Temperature: ");
Serial.print(get3231Temp());
Serial.println(" C");
// Push the hour 2 digits to the left by multiplying 100
disp = (hour * 100) + minute;
g_numberToDisplay = disp;
if (g_numberToDisplay < 10)
{
g_registerArray [0] = g_digits [0];
g_registerArray [1] = g_digits [0];
g_registerArray [2] = g_digits [0];
g_registerArray [3] = g_digits [g_numberToDisplay];
}
else if (g_numberToDisplay < 100)
{
g_registerArray [0] = g_digits [0];
g_registerArray [1] = g_digits [0];
g_registerArray [2] = g_digits [g_numberToDisplay / 10];
g_registerArray [3] = g_digits [g_numberToDisplay % 10];
}
else if (g_numberToDisplay < 1000)
{
g_registerArray [0] = g_digits [0];
g_registerArray [1] = g_digits [g_numberToDisplay / 100];
g_registerArray [2] = g_digits [(g_numberToDisplay % 100) / 10];
g_registerArray [3] = g_digits [g_numberToDisplay % 10];
}
else
{
g_registerArray [0] = g_digits [g_numberToDisplay / 1000];
g_registerArray [1] = g_digits [(g_numberToDisplay % 1000) / 100];
g_registerArray [2] = g_digits [(g_numberToDisplay % 100) / 10];
g_registerArray [3] = g_digits [g_numberToDisplay % 10];
}
// Read the DHT11 sensors
int span = 10;
int aRead = 0;
// Display Temp every 10 secs
if ( (sec == 0) || (sec == 10) || (sec == 20) || (sec == 30) ||
(sec == 40) || (sec == 50) ) {
// Get DHT temp & humid
byte temp = get3231Temp();
// Adjust DHT11 temp + 1
// Debugging to serial
Serial.print("humdity = ");
Serial.print(humid, DEC);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(temp, DEC);
Serial.println("C ");
// Push the 2 digit temp, degree symbol & Char C to the 7-segment LED
g_registerArray [0] = g_digits [temp / 10];
g_registerArray [1] = g_digits [temp % 10];
g_registerArray [2] = g_digits [90]; // Degree symbol
g_registerArray [3] = g_digits [91]; // C
sendSerialData (g_registers, g_registerArray);
// Blink the LED connected to pin 13
digitalWrite(ledPin,HIGH);
delay(1000);
digitalWrite(ledPin,LOW);
delay(1000);
}
// The below codes display the internal voltmeter readings
if ( (sec == 2) || (sec == 12) || (sec == 22) || (sec == 32) ||
(sec == 42) || (sec == 52) ) {
// get the internal voltage in four digits
// Serial debugging
// push the voltage to the 7-segment four digits
sendSerialData (g_registers, g_registerArray);
}
else {
// Display time
sendSerialData (g_registers, g_registerArray);
}
// Blink the LED on pin 13 every seconds
digitalWrite(ledPin,HIGH);
delay(1000);
digitalWrite(ledPin,LOW);
delay(1000);
}
Чт сен 10, 2020 18:24:27
byte g_digits [10]; // Definitions of the 7-bit values for displaying digits
g_digits [90] = a + d + e + c; // Degree dot
Чт сен 10, 2020 21:10:04
Сб сен 12, 2020 07:01:22
Не забываем сворачивать исходник в спойлер (или прикреплять файлом приложения).
Пт окт 30, 2020 16:52:28
Сб окт 31, 2020 19:02:25
Вс ноя 01, 2020 14:30:27
Чт ноя 12, 2020 11:34:25
Ср ноя 18, 2020 13:12:43
Ср ноя 18, 2020 15:32:47
Ср ноя 18, 2020 18:51:00
Чт ноя 19, 2020 02:33:16
Чт ноя 19, 2020 15:07:44
Чт ноя 19, 2020 15:25:02
Чт ноя 19, 2020 15:30:59
Чт ноя 19, 2020 22:23:05
Пт ноя 20, 2020 02:39:40
Пт ноя 20, 2020 07:34:47