Help With my first project?
this first project arduino. familiar if statements , variables , such 2 , half years of working tasker android. first project arduino control tv using arduino xbee , tasker. have basics figured out but, hit hickup. when try power on , off or channel or down ect. have no issues when put them in code stuck ir led on , never shutting off? here example of code using... did wrong appriciated.
// see full tutorial @ http://www.ladyada.net/learn/sensors/ir.html
// code public domain, please enjoy!
int irledpin = 13;
void setup() {
serial.begin(9600);
pinmode(irledpin, output);
serial.println("ready");
}
void loop()
{
delay(10);
onoffcode();
if (serial.available() > 0)
{
int data = serial.read(); // read incoming byte:
switch(data)
{
case 'a' : serial.println("on/off"); onoffcode(); break;
case 's' : serial.println("channel up"); programpluscode(); break;
case 'd' : serial.println("channel down"); programminuscode(); break;
case 'f' : serial.println("volume up"); volumepluscode(); break;
case 'g' : serial.println("volume down"); volumeminuscode(); break;
case 'h' : serial.println("mute"); mutecode(); break;
default : serial.println("invalid character"); break;
}
}
}
void pulseir(long microsecs) {
// we'll count down number of microseconds told wait
cli(); // turns off background interrupts
while (microsecs > 0) {
// 38 khz 13 microseconds high , 13 microseconds low
digitalwrite(irledpin, high); // takes 3 microseconds happen
delaymicroseconds(10); // hang out 10 microseconds, can change 9 if not working
digitalwrite(irledpin, low); // takes 3 microseconds
delaymicroseconds(10); // hang out 10 microseconds, can change 9 if not working
// 26 microseconds altogether
microsecs -= 26;
}
sei(); // turns them on
}
void onoffcode() {
delaymicroseconds(34496);
pulseir(880);
delaymicroseconds(860);
pulseir(880);
delaymicroseconds(840);
pulseir(1780);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(860);
pulseir(880);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(1720);
pulseir(900);
delaymicroseconds(840);
pulseir(1780);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(23464);
pulseir(900);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(860);
pulseir(1760);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(860);
pulseir(880);
delaymicroseconds(860);
pulseir(880);
delaymicroseconds(860);
pulseir(880);
delaymicroseconds(860);
pulseir(880);
delaymicroseconds(1720);
pulseir(880);
delaymicroseconds(860);
pulseir(1780);
delaymicroseconds(820);
pulseir(880);
}
void programpluscode() {
delaymicroseconds(44020);
pulseir(900);
delaymicroseconds(840);
pulseir(1760);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(860);
pulseir(920);
delaymicroseconds(820);
pulseir(880);
delaymicroseconds(860);
pulseir(900);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(1700);
pulseir(1780);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(840);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(23424);
pulseir(920);
delaymicroseconds(840);
pulseir(1800);
delaymicroseconds(800);
pulseir(900);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(860);
pulseir(900);
delaymicroseconds(820);
pulseir(880);
delaymicroseconds(1740);
pulseir(1800);
delaymicroseconds(800);
pulseir(920);
delaymicroseconds(820);
pulseir(880);
delaymicroseconds(860);
pulseir(900);
}
void programminuscode() {
delaymicroseconds(6692);
pulseir(920);
delaymicroseconds(820);
pulseir(880);
delaymicroseconds(860);
pulseir(1760);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(860);
pulseir(920);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(1720);
pulseir(1800);
delaymicroseconds(800);
pulseir(900);
delaymicroseconds(840);
pulseir(920);
delaymicroseconds(820);
pulseir(880);
delaymicroseconds(1720);
pulseir(920);
delaymicroseconds(22584);
pulseir(920);
delaymicroseconds(820);
pulseir(880);
delaymicroseconds(860);
pulseir(1780);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(880);
delaymicroseconds(860);
pulseir(920);
delaymicroseconds(1680);
pulseir(1780);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(840);
pulseir(920);
delaymicroseconds(1700);
pulseir(880);
}
void volumepluscode() {
delaymicroseconds(57164);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(1800);
delaymicroseconds(800);
pulseir(920);
delaymicroseconds(820);
pulseir(9200);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(840);
pulseir(920);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(1700);
pulseir(1800);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(23444);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(1800);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(1680);
pulseir(1820);
delaymicroseconds(800);
pulseir(900);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(840);
pulseir(900);
}
void volumeminuscode() {
delaymicroseconds(22168);
pulseir(920);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(840);
pulseir(1800);
delaymicroseconds(800);
pulseir(920);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(1700);
pulseir(1800);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(1700);
pulseir(900);
delaymicroseconds(22584);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(1800);
delaymicroseconds(800);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(840);
pulseir(920);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(1700);
pulseir(1800);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(1700);
pulseir(900);
}
void mutecode() {
delaymicroseconds(21172);
pulseir(900);
delaymicroseconds(820);
pulseir(1800);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(1700);
pulseir(920);
delaymicroseconds(820);
pulseir(1780);
delaymicroseconds(1700);
pulseir(900);
delaymicroseconds(22584);
pulseir(920);
delaymicroseconds(820);
pulseir(1800);
delaymicroseconds(800);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(1700);
pulseir(900);
delaymicroseconds(840);
pulseir(1800);
delaymicroseconds(1660);
pulseir(900);
}
// see full tutorial @ http://www.ladyada.net/learn/sensors/ir.html
// code public domain, please enjoy!
int irledpin = 13;
void setup() {
serial.begin(9600);
pinmode(irledpin, output);
serial.println("ready");
}
void loop()
{
delay(10);
onoffcode();
if (serial.available() > 0)
{
int data = serial.read(); // read incoming byte:
switch(data)
{
case 'a' : serial.println("on/off"); onoffcode(); break;
case 's' : serial.println("channel up"); programpluscode(); break;
case 'd' : serial.println("channel down"); programminuscode(); break;
case 'f' : serial.println("volume up"); volumepluscode(); break;
case 'g' : serial.println("volume down"); volumeminuscode(); break;
case 'h' : serial.println("mute"); mutecode(); break;
default : serial.println("invalid character"); break;
}
}
}
void pulseir(long microsecs) {
// we'll count down number of microseconds told wait
cli(); // turns off background interrupts
while (microsecs > 0) {
// 38 khz 13 microseconds high , 13 microseconds low
digitalwrite(irledpin, high); // takes 3 microseconds happen
delaymicroseconds(10); // hang out 10 microseconds, can change 9 if not working
digitalwrite(irledpin, low); // takes 3 microseconds
delaymicroseconds(10); // hang out 10 microseconds, can change 9 if not working
// 26 microseconds altogether
microsecs -= 26;
}
sei(); // turns them on
}
void onoffcode() {
delaymicroseconds(34496);
pulseir(880);
delaymicroseconds(860);
pulseir(880);
delaymicroseconds(840);
pulseir(1780);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(860);
pulseir(880);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(1720);
pulseir(900);
delaymicroseconds(840);
pulseir(1780);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(23464);
pulseir(900);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(860);
pulseir(1760);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(860);
pulseir(880);
delaymicroseconds(860);
pulseir(880);
delaymicroseconds(860);
pulseir(880);
delaymicroseconds(860);
pulseir(880);
delaymicroseconds(1720);
pulseir(880);
delaymicroseconds(860);
pulseir(1780);
delaymicroseconds(820);
pulseir(880);
}
void programpluscode() {
delaymicroseconds(44020);
pulseir(900);
delaymicroseconds(840);
pulseir(1760);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(860);
pulseir(920);
delaymicroseconds(820);
pulseir(880);
delaymicroseconds(860);
pulseir(900);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(1700);
pulseir(1780);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(840);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(23424);
pulseir(920);
delaymicroseconds(840);
pulseir(1800);
delaymicroseconds(800);
pulseir(900);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(860);
pulseir(900);
delaymicroseconds(820);
pulseir(880);
delaymicroseconds(1740);
pulseir(1800);
delaymicroseconds(800);
pulseir(920);
delaymicroseconds(820);
pulseir(880);
delaymicroseconds(860);
pulseir(900);
}
void programminuscode() {
delaymicroseconds(6692);
pulseir(920);
delaymicroseconds(820);
pulseir(880);
delaymicroseconds(860);
pulseir(1760);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(860);
pulseir(920);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(1720);
pulseir(1800);
delaymicroseconds(800);
pulseir(900);
delaymicroseconds(840);
pulseir(920);
delaymicroseconds(820);
pulseir(880);
delaymicroseconds(1720);
pulseir(920);
delaymicroseconds(22584);
pulseir(920);
delaymicroseconds(820);
pulseir(880);
delaymicroseconds(860);
pulseir(1780);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(880);
delaymicroseconds(860);
pulseir(920);
delaymicroseconds(1680);
pulseir(1780);
delaymicroseconds(840);
pulseir(880);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(840);
pulseir(920);
delaymicroseconds(1700);
pulseir(880);
}
void volumepluscode() {
delaymicroseconds(57164);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(1800);
delaymicroseconds(800);
pulseir(920);
delaymicroseconds(820);
pulseir(9200);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(840);
pulseir(920);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(1700);
pulseir(1800);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(23444);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(1800);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(1680);
pulseir(1820);
delaymicroseconds(800);
pulseir(900);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(840);
pulseir(900);
}
void volumeminuscode() {
delaymicroseconds(22168);
pulseir(920);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(840);
pulseir(1800);
delaymicroseconds(800);
pulseir(920);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(1700);
pulseir(1800);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(1700);
pulseir(900);
delaymicroseconds(22584);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(1800);
delaymicroseconds(800);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(840);
pulseir(920);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(1700);
pulseir(1800);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(1700);
pulseir(900);
}
void mutecode() {
delaymicroseconds(21172);
pulseir(900);
delaymicroseconds(820);
pulseir(1800);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(1700);
pulseir(920);
delaymicroseconds(820);
pulseir(1780);
delaymicroseconds(1700);
pulseir(900);
delaymicroseconds(22584);
pulseir(920);
delaymicroseconds(820);
pulseir(1800);
delaymicroseconds(800);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(820);
pulseir(900);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(840);
pulseir(900);
delaymicroseconds(820);
pulseir(920);
delaymicroseconds(1700);
pulseir(900);
delaymicroseconds(840);
pulseir(1800);
delaymicroseconds(1660);
pulseir(900);
}
it considerably in reading , understanding code if put in code tags having auto formatted , removed superfluous blank lines suggested in the sticky @ top of forum.
i have not looked @ code in detail first thing noticed clumsy way in ir pulses generated many, many lines of similar code. why not put values in arrays , iterate through them loop ? if nothing else make program easier read.
i have not looked @ code in detail first thing noticed clumsy way in ir pulses generated many, many lines of similar code. why not put values in arrays , iterate through them loop ? if nothing else make program easier read.
Arduino Forum > Using Arduino > Programming Questions > Help With my first project?
arduino
Comments
Post a Comment