Есть модуль часов DS3231 подключенный к Ардуино Уно по I2C, задача вывести время и дату на 6 разрядов семи-сегментных индикаторах подключенные по SPI подключенных через каскад сдвиговых регистров 74HC595. На фото скетч только под индикаторы.
#include "Wire.h"
#include <DS3231.h>
#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return( (val/16*10) + (val%16) );
}
const byte latchPin=6;//st
const byte clockPin=7;//sh
const byte dataPin=5;//ds
// binary code for shift register & 7segment indicator
byte number[] = {0b10001000,0b10111011, 0b00011100, 0b00011001, 0b00101011, 0b01001001, 0b01001000, 0b10011011, 0b00001000, 0b00001001};
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
Wire.begin();
Serial.begin(9600);
}
void loop()
{
{
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
{
*second = bcdToDec(Wire.read());
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read());
byte second, minute, hour;
read DS3231 time(&second, &minute, &hour);
}
//Присваеваем значение для переменных
int h1 = hour / 10;
int h2 = hour % 10;
int m1 = minute() / 10;
int m2 = minute() % 10;
int s1 = second() / 10;
int s2 = second() % 10;
}
digitalWrite(latchPin,LOW);
shiftOut(dataPin, clockPin, LSBFIRST, number[s2]);
shiftOut(dataPin, clockPin, LSBFIRST, number[s1]);
shiftOut(dataPin, clockPin, LSBFIRST, number[m2]);
shiftOut(dataPin, clockPin, LSBFIRST, number[m1]);
shiftOut(dataPin, clockPin, LSBFIRST, number[h2]);
shiftOut(dataPin, clockPin, LSBFIRST, number[h1]);
digitalWrite(latchPin,HIGH);
delay(500);
}
Вылезает куча ошибок
LED_Clock2.ino: In function 'void loop()':
LED_Clock2:36: error: 'second' was not declared in this scope
LED_Clock2:37: error: 'minute' was not declared in this scope
LED_Clock2:38: error: 'hour' was not declared in this scope
LED_Clock2:41: error: 'read' was not declared in this scope
LED_Clock2:41: error: expected ';' before 'DS3231'
LED_Clock2:44: error: 'hour' was not declared in this scope
LED_Clock2:46: error: 'minute' was not declared in this scope
LED_Clock2:48: error: 'second' was not declared in this scope
LED_Clock2.ino:44:5: warning: unused variable 'h1' [-Wunused-variable]
LED_Clock2.ino:45:5: warning: unused variable 'h2' [-Wunused-variable]
LED_Clock2.ino:46:5: warning: unused variable 'm1' [-Wunused-variable]
LED_Clock2.ino:47:5: warning: unused variable 'm2' [-Wunused-variable]
LED_Clock2.ino:48:5: warning: unused variable 's1' [-Wunused-variable]
LED_Clock2.ino:49:5: warning: unused variable 's2' [-Wunused-variable]
LED_Clock2:53: error: 's2' was not declared in this scope
LED_Clock2:54: error: 's1' was not declared in this scope
LED_Clock2:55: error: 'm2' was not declared in this scope
LED_Clock2:56: error: 'm1' was not declared in this scope
LED_Clock2:57: error: 'h2' was not declared in this scope
LED_Clock2:58: error: 'h1' was not declared in this scope
'second' was not declared in this scope
Помогите с правкой скетча


Присоединяйтесь — мы покажем вам много интересного
Присоединяйтесь к ОК, чтобы подписаться на группу и комментировать публикации.
Комментарии 26