Giter Club home page Giter Club logo

electronic's People

Watchers

Pye Phyo avatar

electronic's Issues

iR clt Relay 2.uno

#include <IRremote.h>
const int RECV_PIN=11;
IRrecv irrecv(RECV_PIN);
decode_results results;
#define IN1 3
#define IN2 4
#define IN3 5
#define IN4 6
bool i=false;
bool j=false;
bool k=false;
bool l=false;
bool m=false;
void setup()
{
Serial.begin(9600);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
irrecv.enableIRIn();
irrecv.blink13(true);

}
void loop()
{
if (irrecv.decode(&results))
{
Serial.println(results.value,HEX);
delay(100);
/////////////////////////
if(results.value==0x40BD00FF)
{
i=!i;
digitalWrite(IN1, i);

 }
 ////////////////////////
 if(results.value==0x40BD807F)
 {
    j=!j;
    digitalWrite(IN2, j);
    
   // delay(200);
 }
 if(results.value==0x40BD40BF)
 {
    k=!k;
    digitalWrite(IN3, k);
    
   // delay(200);
 }  
 //////////////////////////////
 if(results.value==0x40BDC03F)
 {
    l=!l;
    digitalWrite(IN4, l);
    
   // delay(200);
 }
 //////////////////////
 if(results.value==0x40BD28D7)
 {
    m=!m;
    digitalWrite(IN1, m);
    digitalWrite(IN2, m);
    digitalWrite(IN3, m);
    digitalWrite(IN4, m);
    
   // delay(200);
 }
 irrecv.resume(); // Receive the next value
 //delay(100);

}
}

iR ctl Relay

#include <IRremote.h>

const int IR_PIN = 2;

const int RELAY_PINS[8] = {12, 11, 10, 9, 8, 7, 6, 5};
int RELAY_STATES[8] = {LOW};

IRrecv irrecv(IR_PIN);

decode_results results;

void setup() {
irrecv.enableIRIn();

for (int i = 0; i < 8; i++) {
pinMode(RELAY_PINS[i], OUTPUT);
}
}

/**

  • Decode IR code to numeric button 0-9
  • Return pressed button number or -1
    */
    int samsungDecode(unsigned long irValue) {
    switch (irValue) {
    case 0xE0E020DF:
    return 1;
    case 0xE0E0A05F:
    return 2;
    case 0xE0E0609F:
    return 3;
    case 0xE0E010EF:
    return 4;
    case 0xE0E0906F:
    return 5;
    case 0xE0E050AF:
    return 6;
    case 0xE0E030CF:
    return 7;
    case 0xE0E0B04F:
    return 8;
    case 0xE0E0708F:
    return 9;
    case 0xE0E08877:
    return 0;
    }
    return -1;
    }

/**

  • Toggle single relay or switch ON/OFF all relays
    */
    void action(int button) {
    if (button > 0 && button < 9) {
    //toggle single relay
    int i = button - 1;
    if (RELAY_STATES[i] == LOW) {
    digitalWrite(RELAY_PINS[i], HIGH);
    RELAY_STATES[i] = HIGH;
    } else {
    digitalWrite(RELAY_PINS[i], LOW);
    RELAY_STATES[i] = LOW;
    }
    } else if (button == 9) {
    //switch ON all relays
    for (int i = 0; i < 8; i++) {
    digitalWrite(RELAY_PINS[i], HIGH);
    RELAY_STATES[i] = HIGH;
    }
    } else if (button == 0) {
    //switch OFF all relays
    for (int i = 0; i < 8; i++) {
    digitalWrite(RELAY_PINS[i], LOW);
    RELAY_STATES[i] = LOW;
    }
    }
    }

int lastPressedButton = -1;

void loop() {
if (irrecv.decode(&results)) {
int button = samsungDecode(results.value);
if (button != lastPressedButton) {
lastPressedButton = button;
action(button);
}
irrecv.resume();
} else {
lastPressedButton = -1;
}
delay(250);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.