Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- #include <IRremote.h>
- #define BRIGHTNESS 6
- #define RECV_PIN 10
- #define ALARM_BUZZER 8
- IRrecv irrecv(RECV_PIN);
- decode_results results;
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- volatile int seconds = 0;
- volatile int minutes = 0;
- volatile int hours = 0;
- void setup(){
- lcd.begin(16, 2);
- Serial.begin(9600);
- irrecv.enableIRIn();
- digitalWrite(BRIGHTNESS, 100);
- pinMode(8, OUTPUT);
- pinMode(13, OUTPUT);
- pinMode(BRIGHTNESS, OUTPUT);
- cli();
- TCCR1A = 0;
- TCCR1B = 0;
- OCR1A = 15625;
- TCCR1B |= (1 << WGM12);
- TCCR1B |= (1 << CS10);
- TCCR1B |= (1 << CS12);
- TIMSK1 |= (1<< OCIE1A);
- sei();
- }
- void loop(){
- if(irrecv.decode(&results)) {
- long controlValue = results.value;
- if(controlValue == 0xFF629D){
- setTime();
- }
- }
- irrecv.resume();
- brightness();
- alarmBuzzer();
- }
- ISR (TIMER1_COMPA_vect){
- time();
- }
- ISR (TIMER1_OVF_vect){
- time();
- }
- void time(){
- lcd.setCursor(0,0);
- if(hours < 10){
- lcd.print(0);
- }
- lcd.print(hours);
- lcd.print(":");
- if(minutes < 10){
- lcd.print(0);
- }
- lcd.print(minutes);
- lcd.print(":");
- if(seconds < 10){
- lcd.print(0);
- }
- lcd.print(seconds);
- seconds++;
- if(seconds == 60){
- minutes++;
- seconds = 0;
- if(minutes == 60){
- hours++;
- minutes = 0;
- }
- }
- if (hours >= 24){
- hours = 0;
- }
- }
- void brightness(){
- if(hours >= 8 && hours < 21){
- analogWrite(6, 100);
- }else{
- analogWrite(6, 5);
- }
- }
- void alarmBuzzer(){
- digitalWrite(8, HIGH);
- delay(500);
- digitalWrite(8, LOW);
- delay(500);
- }
- void setTime(){
- long control = 0;
- while( control != 0xFF629D ){
- Serial.print("Change Time");
- hours = remoteControl();
- Serial.print(hours);
- Serial.print(" num1 \n");
- hours = hours * 10;
- hours = hours + remoteControl();
- Serial.print(hours);
- Serial.print(" num2 \n");
- minutes = remoteControl();
- Serial.print(minutes);
- Serial.print(" num3 \n");
- minutes = minutes * 10;
- Serial.print(minutes);
- Serial.print(" num4 \n");
- minutes = minutes + remoteControl();
- seconds = 0;
- time();
- control = 0xFF629D;
- }
- }
- int remoteControl(){
- irrecv.resume();
- while(!irrecv.decode(&results)){
- if(irrecv.decode(&results)) {
- long controlValue = results.value;
- switch(controlValue){
- //button setTime = mode
- //button 0
- case 0xFF6897:
- return 0;
- //button 1
- case 0xFF30CF:
- return 1;
- //button 2
- case 0xFF18E7:
- return 2;
- //button 3
- case 0xFF7A85:
- return 3;
- //button 4
- case 0xFF10EF:
- return 4;
- //button 5
- case 0xFF38C7:
- return 5;
- //button 6
- case 0xFF5AA5:
- return 6;
- //button 7
- case 0xFF42BD:
- return 7;
- //button 8
- case 0xFF4AB5:
- return 8;
- //button 9
- case 0xFF52AD:
- return 9;
- //Holding down any button
- case 0xFFFFFFFF:
- delay(500);
- break;
- default:
- break;
- }
- irrecv.resume(); // Receive the next value
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement