Hello everyone, I'm trying to make a simple device that will turn off a tv whenever the light level in a room reaches a certain point. Currently as a learning project I have built (based on a tutorial) a 7 segment display showing 0-9 mapped to the value of a photoresistor. I thought it would be cool to have this same sketch send out an IR code whenever the light level stayed below a certain amount for a few minutes. I have barely any knowledge in writing sketches. Any hints on how to combine these two sketches and also modifying the IRsend part to use a different pin like 7 and only activating when the analog value of the photo resistor reaches <300?
Thanks abunch I know all this seems noobish, but I really want to learn how to do this properly. Thanks so much.
/*
* IRremote: IRsendDemo - demonstrates sending IR codes with IRsend
* An IR LED must be connected to Arduino PWM pin 3.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
#include <IRremote.h>
IRsend irsend;
void setup()
{
}
void loop() {
if (Serial.read() != -1) {
for (int i = 0; i < 3; i++) {
irsend.sendSony(0xa90, 12); // Sony TV power code
delay(100);
}
}
}
and
#define PHOTO 0
void setup()
{
pinMode(0, OUTPUT); // -> Anode A, bit 0 in the definitions
pinMode(1, OUTPUT); // -> Anode B, bit 1
pinMode(2, OUTPUT); // -> Anode C, bit 2
pinMode(3, OUTPUT); // -> Anode D, bit 3
pinMode(4, OUTPUT); // -> Anode E, bit 4
pinMode(5, OUTPUT); // -> Anode F, bit 5
pinMode(6, OUTPUT); // -> Anode G, bit 6
}
// encode the on/off state of the LED segments for the characters
// '0' to '9' into the bits of the bytes
const byte numDef[10] = { 192, 249, 164, 176, 153, 146, 131, 248, 128, 152 };
// keep track of the old value
int oldVal = -1;
void loop()
{
// grab the input from the photoresistor
int input = analogRead(PHOTO);
// convert the input range (0-1023) to the range we can
// display on the LED (0-9)
int displayVal = map(input, 0, 1023, 0, 9);
// if the value has changed, then update the LED and hold for a
// brief moment to help with the debouncing.
if (displayVal != oldVal)
{
setSegments( numDef[displayVal] );
delay(250);
}
}
void setSegments(byte segments)
{
// for each of the segments of the LED
for (int s = 0; s < 7; s++)
{
int bitVal = bitRead( segments, s ); // grab the bit
digitalWrite(s, bitVal); // set the segment
}
}