FD1642-CT1642-SM1642-ET6227
In this Arduino Tutorial we will learn how
Usage of an 18Bit shift register found in the front panels of
various household electronic appliances ( such as set-top boxes, DVD players or various other LED display devices).
Schema
download |
|
Code: Download
Library
// REQUIRES the following Arduino libraries:
// - CT1642 library: https://github.com/arkroan/CT1642
// - RTC DS1307 Library: https://github.com/MajicDesigns/MD_DS1307
// - IRremote library can be found at https://github.com/z3t0/Arduino-IRremote
// Find All "Great Projects" Videos : https://www.youtube.com/channel/UCCC8DuqicBtP3A_aC53HYDQ/videos
Code
// REQUIRES the following Arduino libraries:
// - CT1642 library: https://github.com/arkroan/CT1642
// - RTC DS1307 Library: https://github.com/MajicDesigns/MD_DS1307
// - IRremote library can be found at https://github.com/z3t0/Arduino-IRremote
// Find All "Great Projects" Videos : https://www.youtube.com/channel/UCCC8DuqicBtP3A_aC53HYDQ/videos
#include <CT1642.h>
#include <time.h>
#include <SPI.h>
#include <IRremote.h>
#define USE_DS1307 0
#include <MD_DS1307.h>
#include <Wire.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
#define CLOCK_PIN 6
#define DATA_PIN 7
CT1642 ledDisplay(CLOCK_PIN, DATA_PIN);
uint32_t lastTime = 0; // millis() memory
bool flasher = false; // seconds passing flasher
uint16_t hours, minutes, second, day, month, year;
int mm1, mm2, d1, d2;
int h1, h2, m1, m2;
int y1, y2, y3, y4;
int s1, s2;
int mode = 0;
void getTime(){
RTC.readTime();
minutes = RTC.m;
hours = RTC.h;
h1 = hours / 10;
hours = hours - (h1 * 10);
h2 = hours;
m1 = minutes / 10;
minutes = minutes - (m1 * 10);
m2 = minutes;
}
void getSec(){
RTC.readTime();
second = RTC.s;
s1 = second / 10;
second = second - (s1 * 10);
s2 = second;
}
void getDate(){
RTC.readTime();
month = RTC.mm;
day = RTC.dd;
mm1 = month / 10;
month = month - (mm1 * 10);
mm2 = month;
d1 = day / 10;
day = day - (d1 * 10);
d2 = day;
}
void getYear(){
RTC.readTime();
year = RTC.yyyy;
y1 = year / 1000;
year = year - (y1 * 1000);
y2 = year / 100;
year = year - (y2 * 100);
y3 = year / 10;
year = year - (y3 * 10);
y4 = year;
}
void getresultIR(){
if (irrecv.decode(&results)) {
if (results.value==0x38863BDC){
mode++;
if (mode >= 4 ) {
mode = 0;
}
} else if (results.value==0x38863BF2){
if (mode == 1 ) {
RTC.s = 0;
RTC.writeTime();
}
else if (mode == 4 ) {
RTC.m++;
if (RTC.m >= 60 ) {
RTC.m = 0;
}
RTC.writeTime();
}
else if (mode == 5 ) {
RTC.h++;
if (RTC.h >= 24 ) {
RTC.h = 0;
}
RTC.writeTime();
}
else if (mode == 6 ) {
RTC.dd++;
if (RTC.dd >= 32 ) {
RTC.dd = 1;
}
RTC.writeTime();
}
else if (mode == 7 ) {
RTC.mm++;
if (RTC.mm >= 13 ) {
RTC.mm = 1;
}
RTC.writeTime();
}
else if (mode == 8 ) {
RTC.yyyy++;
if (RTC.yyyy >= 2041 ) {
RTC.yyyy = 2001;
}
RTC.writeTime();
}
} else if (results.value==0x38863BFA){
if (mode <= 3 ) {
mode = 0;
}
else if (mode == 4 ) {
RTC.m--;
if (RTC.m <= 0 ) {
RTC.m = 59;
}
RTC.writeTime();
}
else if (mode == 5 ) {
RTC.h--;
if (RTC.h <= 0 ) {
RTC.h = 23;
}
RTC.writeTime();
}
else if (mode == 6 ) {
RTC.dd--;
if (RTC.dd <= 0 ) {
RTC.dd = 31;
}
RTC.writeTime();
}
else if (mode == 7 ) {
RTC.mm--;
if (RTC.mm <= 0 ) {
RTC.mm = 12;
}
RTC.writeTime();
}
else if (mode == 8 ) {
RTC.yyyy--;
if (RTC.yyyy <= 2000 ) {
RTC.yyyy = 2041;
}
RTC.writeTime();
}
} else if (results.value==0x38863BC2){
mode++;
if (mode >= 9 || mode <= 4) {
mode = 4;
}
} else if (results.value==0x38863BCA){
mode--;
if (mode <= 3) {
mode = 8;
}
}
irrecv.resume(); // Receive the next value
}
}
void setup() {
irrecv.enableIRIn(); // Start the receiver
RTC.control(DS1307_CLOCK_HALT, DS1307_OFF);
RTC.control(DS1307_12H, DS1307_OFF);
RTC.readTime();
}
void loop() {
getresultIR();
if (mode == 0) {
if (millis() - lastTime >= 1000)
{
lastTime = millis();
getTime();
flasher = !flasher;
}
if (flasher) {
ledDisplay.showChars(' ', 3);
}
ledDisplay.showSingle(h1, 4);
ledDisplay.showSingle(h2, 3);
ledDisplay.showSingle(m1, 2);
ledDisplay.showSingle(m2, 1);
}
else if (mode == 1) {
if (millis() - lastTime >= 1000)
{
lastTime = millis();
getSec();
flasher = !flasher;
}
if (flasher) {
ledDisplay.showChars(' ', 3);
}
ledDisplay.showSingle(s1, 2);
ledDisplay.showSingle(s2, 1);
}
else if (mode == 2) {
getDate();
ledDisplay.showSingle(d2, 1);
ledDisplay.showSingle(d1, 2);
ledDisplay.showSingle(mm2, 3);
if (mm1 == 0) {
ledDisplay.showChars('0', 4);
}else
ledDisplay.showSingle(mm1, 4);
}
else if (mode == 3) {
getYear();
ledDisplay.showChars(' ', 1);
ledDisplay.showSingle(y1, 4);
ledDisplay.showSingle(y2, 3);
ledDisplay.showSingle(y3, 2);
ledDisplay.showSingle(y4, 1);
}
else if (mode == 4) {
if (millis() - lastTime >= 300)
{
lastTime = millis();
getTime();
flasher = !flasher;
}
if (flasher)
{
ledDisplay.showChars(' ', 3);
ledDisplay.showSingle(h1, 4);
ledDisplay.showSingle(h2, 3);
ledDisplay.showSingle(m1, 2);
ledDisplay.showSingle(m2, 1);
} else
ledDisplay.showSingle(h1, 4);
ledDisplay.showSingle(h2, 3);
}
else if (mode == 5) {
if (millis() - lastTime >= 300)
{
lastTime = millis();
getTime();
flasher = !flasher;
}
if (flasher)
{
ledDisplay.showChars(' ', 3);
ledDisplay.showSingle(h1, 4);
ledDisplay.showSingle(h2, 3);
ledDisplay.showSingle(m1, 2);
ledDisplay.showSingle(m2, 1);
} else
ledDisplay.showSingle(m1, 2);
ledDisplay.showSingle(m2, 1);
}
else if (mode == 6) {
if (millis() - lastTime >= 300)
{
lastTime = millis();
getDate();
flasher = !flasher;
}
if (flasher)
{
ledDisplay.showSingle(d2, 1);
ledDisplay.showSingle(d1, 2);
ledDisplay.showSingle(mm2, 3);
if (mm1 == 0) {
ledDisplay.showChars('0', 4);
}else
ledDisplay.showSingle(mm1, 4);
} else
ledDisplay.showChars(' ', 1);
ledDisplay.showSingle(mm2, 3);
if (mm1 == 0) {
ledDisplay.showChars('0', 4);
}else
ledDisplay.showSingle(mm1, 4);
}
else if (mode == 7) {
if (millis() - lastTime >= 300)
{
lastTime = millis();
getDate();
flasher = !flasher;
}
if (flasher)
{
ledDisplay.showSingle(d2, 1);
ledDisplay.showSingle(d1, 2);
ledDisplay.showSingle(mm2, 3);
if (mm1 == 0) {
ledDisplay.showChars('0', 4);
}else
ledDisplay.showSingle(mm1, 4);
} else
ledDisplay.showChars(' ', 1);
ledDisplay.showSingle(d1, 2);
ledDisplay.showSingle(d2, 1);
}
else if (mode == 8) {
if (millis() - lastTime >= 300)
{
lastTime = millis();
getYear();
getYear();
flasher = !flasher;
}
if (flasher)
{
ledDisplay.showSingle(y1, 4);
ledDisplay.showSingle(y2, 3);
ledDisplay.showSingle(y3, 2);
ledDisplay.showSingle(y4, 1);
} else
ledDisplay.showChars(' ', 1);
}
}
text
void showChars(char char1, int digit);
void CT1642::showChars(char char1, int digit){
write(getCharByte(char1)|DATA_DOT, digit);
delay(povDelay);
}