управление светом от ик, bluetooch и ttp223B. помогите
- Войдите на сайт для отправки комментариев
Втр, 11/10/2016 - 17:57
управление светом от ик, bluetooch нс 06 и ttp223B
по отдельности все работает, а вот всесте только сенсор ttp 223.
#include <IRremote.h>
int RECV_PIN = 6; //вход ИК приемника
IRrecv irrecv(RECV_PIN);
decode_results results;
const int rele = 8; //реле 8 вывод
const int buttonPin = 2;
int val;
int ledState = HIGH; //+
int buttonState; //+
int lastButtonState = LOW; //+
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0; //+
long debounceDelay = 50; //+
void setup(){
{
digitalWrite(rele, LOW);
}
{
irrecv.enableIRIn(); // включить приемник
}
pinMode(rele, OUTPUT); //реле на управление светом
pinMode(buttonPin, INPUT); //+
}
void loop()
{
{
od();
}
{
dva();
}
{
tri();
}
}
void od()
{
if (irrecv.decode(&results))
{
if (results.value == 0x2FD807F) //код моей кнопки "2FD807F". У Вас он будет дугой
{
digitalWrite(rele, HIGH);
}
if (results.value == 0x2FD40BF)//код моей кнопки "2FD40BF". У Вас он будет дугой
{
digitalWrite(rele, LOW);
}
irrecv.resume();
}
}
void dva()
{
if (Serial.available())
{
val = Serial.read();
// При символе "1" включаем светодиод
if (val == '1')
{
digitalWrite(rele, HIGH);
}
// При символе "0" выключаем светодиод
if ( val == '0')
{
digitalWrite(rele, LOW);
}
}
}
void tri() //+
{
// read the state of the switch into a local variable:
int reading = digitalRead(buttonPin);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;
// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
ledState = !ledState;
}
}
}
// set the LED:
digitalWrite(rele, ledState);
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonState = reading;
}
плата UNO