//#include <DHT.h>
#define NUMBER_OF_LED 8
const uint8_t latchPin = 22; //latch pin of the 74HC595
const uint8_t clockPin = 23; //clock pin of the 74HC595
const uint8_t dataPinDigit1 = 53; //data pin of the 74HC595 DISPLAY 1
const uint8_t dataPinDigit2 = 52; //data pin of the 74HC595 DISPLAY 2
const uint8_t dataPinDigit3 = 51; //data pin of the 74HC595 DISPLAY 3
const uint8_t dataPinDigit4 = 50; //data pin of the 74HC595 DISPLAY 4
const uint8_t dataPinDigit5 = 49; //data pin of the 74HC595 DISPLAY 5
const uint8_t dataPinDigit6 = 48; //data pin of the 74HC595 DISPLAY 6
uint8_t buttonState = 0;
/*-----------------------------
/* MUX pins
const uint8_t signalPin = 53 ;
const uint8_t S0 = 52 ;
const uint8_t S1 = 51 ;
const uint8_t S2 = 50 ;
const uint8_t S3 = 49 ;
const uint16_t muxChannel[16][4]={
{0,0,0,0}, //channel 0
{1,0,0,0}, //channel 1
{0,1,0,0}, //channel 2
{1,1,0,0}, //channel 3
{0,0,1,0}, //channel 4
{1,0,1,0}, //channel 5
{0,1,1,0}, //channel 6
{1,1,1,0}, //channel 7
{0,0,0,1}, //channel 8
{1,0,0,1}, //channel 9
{0,1,0,1}, //channel 10
{1,1,0,1}, //channel 11
{0,0,1,1}, //channel 12
{1,0,1,1}, //channel 13
{0,1,1,1}, //channel 14
{1,1,1,1} //channel 15
};
void muxSetStatus(int channel ){
digitalWrite(S0, muxChannel[channel][0]);
digitalWrite(S1, muxChannel[channel][1]);
digitalWrite(S2, muxChannel[channel][2]);
digitalWrite(S3, muxChannel[channel][3]);
}
------------------------------*/
//-----------------------------------------------------------------
// Define the pins for the rotary encoder
const int pinA = 2; // Encoder pin A
const int pinB = 3; // Encoder pin B
// Variables to store the previous and current state of pinA
int lastStateA = LOW;
int currentStateA;
// Function to decode the rotary encoder
int decodeRotaryEncoder() {
// Read the current state of pinA
currentStateA = digitalRead(pinA);
// Check if the state of pinA has changed
if (currentStateA != lastStateA) {
// If pinA changed to HIGH, check pinB to determine direction
if (currentStateA == HIGH) {
if (digitalRead(pinB) == LOW) {
// Turning to the right
return 1;
} else {
// Turning to the left
return 0;
}
}
}
// Update lastStateA to the current state for the next loop
lastStateA = currentStateA;
// No rotation detected
return -1;
}
uint8_t increasePin = 12 ; uint8_t decreasePin = 13 ;
uint8_t currentTemp;
uint8_t targetTemp;
uint8_t currentHumidity;
uint8_t targetHumidity;
const static uint8_t digits [11] {
0B11111100, // digit 0
0B01100000, // digit 1
0B11011010, // digit 2
0B11110010, // digit 3
0B01100110, // digit 4
0B10110110, // digit 5
0B10111110, // digit 6
0B11100000, // digit 7
0B11111110, // digit 8
0B11110110, // digit 9
0B00000001 // decimal point
};
const static uint8_t decimal = 0B00000001 ;
const static uint8_t blank = 0B00000000 ;
const static uint8_t letter [4][8] {
0B000011000, // letter i
0B111011000, // letter n
0B011011100, // letter H
0B00000010 , // minus
0B000111100 // letter t
};
uint8_t digitToByte(int preOP) {
switch (preOP)
{
//default: 0B11111100;
case 0: return 0B11111100;
break;
case 1: return 0B01100000;
break;
case 2: return 0B11011010;
break;
case 3: return 0B11110010;
break;
case 4: return 0B01100110;
break;
case 5: return 0B10110110;
break;
case 6: return 0B10111110;
break;
case 7: return 0B11100000;
break;
case 8: return 0B11111110;
break;
case 9: return 0B11110110;
}
}
uint32_t Diagnostic(){
return 10;
}
void LcdDriver(){
}
void SendData(byte data, int pin) {
digitalWrite(latchPin, LOW);
shiftOut(pin, clockPin, LSBFIRST, data);
digitalWrite(latchPin, HIGH);
};
void DigitRoller(int a, int b, int c) {
uint8_t CurrentDigitSegment;
uint8_t CurrentDigitSegment2;
uint8_t CurrentDigitSegment3;
uint8_t NextDigit;
CurrentDigitSegment = a;
CurrentDigitSegment2 = b;
CurrentDigitSegment3 = c;
NextDigit = CurrentDigitSegment + 1;
if (0 <= CurrentDigitSegment < 10) {
NextDigit = CurrentDigitSegment2 + 1;
if (0 <= CurrentDigitSegment2 < 10) {
NextDigit = CurrentDigitSegment3 + 1;
if (0 <= CurrentDigitSegment3 < 10) {
SendData(digits [NextDigit], dataPinDigit3);
CurrentDigitSegment3++;
}
SendData(digits [CurrentDigitSegment2 + 1], dataPinDigit2);
CurrentDigitSegment2++;
}
SendData(digits [CurrentDigitSegment + 1], dataPinDigit1);
CurrentDigitSegment++;
}
}
void increaseDigit() {
byte currentUnit;
//byte current
}
void initialize() {
for (uint8_t i=0 ; i<= 5 ; i++){
for (uint8_t j = 0 ; j <=9; j++){
SendData( digitToByte(j) , 53 - i);
delay(200);
}
SendData( blank , 53 - i);
delay(200);
}
for (uint8_t i=0 ; i<= 5 ; i++){
SendData( decimal , 53 - i);
delay(200);
}
SendData( digitToByte(0) , dataPinDigit1);
SendData( digitToByte(0) , dataPinDigit2);
SendData( digitToByte(0) , dataPinDigit3);
SendData( digitToByte(0) , dataPinDigit4);
SendData( digitToByte(0) , dataPinDigit5);
SendData( digitToByte(0) , dataPinDigit6);
//------------------------------------------
SendData( blank , dataPinDigit1);
SendData( blank , dataPinDigit2);
SendData( blank , dataPinDigit3);
SendData( blank , dataPinDigit4);
SendData( blank , dataPinDigit5);
SendData( blank , dataPinDigit6);
//------------------------------------
SendData( digitToByte(0) , dataPinDigit1);
SendData( digitToByte(0) , dataPinDigit2);
SendData( digitToByte(0) , dataPinDigit3);
SendData( digitToByte(0) , dataPinDigit4);
SendData( digitToByte(0) , dataPinDigit5);
SendData( digitToByte(0) , dataPinDigit6);
delay(200);
SendData( blank , dataPinDigit1);
SendData( blank , dataPinDigit2);
SendData( blank , dataPinDigit3);
SendData( blank , dataPinDigit4);
SendData( blank , dataPinDigit5);
SendData( blank , dataPinDigit6);
delay(200);
SendData( digitToByte(0) , dataPinDigit1);
SendData( digitToByte(0) , dataPinDigit2);
SendData( digitToByte(0) , dataPinDigit3);
SendData( digitToByte(0) , dataPinDigit4);
SendData( digitToByte(0) , dataPinDigit5);
SendData( digitToByte(0) , dataPinDigit6);
delay(100);
SendData( blank , dataPinDigit1);
SendData( blank , dataPinDigit2);
SendData( blank , dataPinDigit3);
SendData( blank , dataPinDigit4);
SendData( blank , dataPinDigit5);
SendData( blank , dataPinDigit6);
}
void incrementNumber(int hundreds, int tens, int units) {
units++;
if (units == 9) {
units = 0;
tens++;
if (tens == 9) {
tens = 0;
hundreds++;
if (hundreds == 9) {
// Reset to 0 if we reached the specified value
hundreds = 0;
tens = 0;
units = 0;
}
}
}
}
uint8_t currentDigitHundreds;
uint8_t currentDigitTens;
uint8_t currentDigitUnits;
struct digitDisplay {
uint8_t hundreds;
uint8_t tens;
uint8_t uints;
} tempDisplay, humidityDisplay;
uint32_t returnDigitFromNumber(uint32_t nbr, uint32_t pos ) {
switch (pos) {
case 1: return nbr / 100;
break;
case 2: return (nbr / 10) % 10;
break;
case 3: return nbr % 10;
}
}
void setup()
{
pinMode(increasePin, INPUT);
pinMode(decreasePin, INPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPinDigit1, OUTPUT);
pinMode(dataPinDigit2, OUTPUT);
pinMode(dataPinDigit3, OUTPUT);
pinMode(dataPinDigit4, OUTPUT);
pinMode(dataPinDigit5, OUTPUT);
pinMode(dataPinDigit6, OUTPUT);
currentDigitHundreds = 0;
currentDigitTens = 0;
currentDigitUnits = 0;
/*--------------------------------------------*/
// decoder block
pinMode(pinA, INPUT);
pinMode(pinB, INPUT);
Serial.begin(9600);
lastStateA = digitalRead(pinA);
/*-----------------------------------*/
/*
SendData(letter[2], dataPinDigit1);
delay(1000);
SendData(blank, dataPinDigit2);
SendData(blank, dataPinDigit3); */
initialize();
currentDigitUnits=5;
}
void loop()
{
increasePin = digitalRead(12);
decreasePin = digitalRead(13);
if (increasePin == HIGH) {
}
if (decreasePin == HIGH) {
//SendData(0B1101110,dataPinDigit3);
}
//currentDigitUnits++;
int result = decodeRotaryEncoder();
if (result == 1 and currentDigitUnits++ < 10) {
currentDigitUnits++;
//Serial.println("Rotary turned to the right");
} else if (result == 0 and currentDigitUnits++ > 0 ) {
currentDigitUnits--;
//Serial.println("Rotary turned to the left");
}
delay(20); // Small delay to debounce
SendData( digitToByte(currentDigitUnits) , dataPinDigit1);
//delay(10);
//SendData( digitToByte(currentDigitUnits) , dataPinDigit2);
//delay(10);
//SendData( digitToByte(currentDigitUnits) , dataPinDigit3);
//delay(10);
}