Sorry to be a pain. I see the line of code but I don't fully understand where to place it. Say it was pin 10 where the LED was placed on the board.
Can I just check everything else with you as well?
// sensible name for when the button is pressed
// use when using a pullup resistor; change LOW to HIGH when using a pulldown resistor
#define ISPRESSED LOW
// number of preser channels
#define NUMPRESETS 6
// maximum number of 'digits' in preset
#define MAXDIGITS 3
#include <IRremote.h>
#include <IRremoteInt.h>
// switch pin
const int switchPin = 2;
// Create IR Send Object
IRsend irsend;
// selected preset
// array with IR codes to be sent
// below contains 2 entries for presets; others default to all zeroes
// if a single digit (e.g. 1 instead of 001) is needed, populate the last one of the 3 and set the others t 0x0000
// this assumes that there is no code that uses 0x0000; you can change it to any unused code
uint16_t presets[NUMPRESETS][MAXDIGITS] =
{
{0x0C06, 0x0C00, 0x0C01}, // preset 1; 601
{0x0C06, 0x0C01, 0x0C04}, // preset 2; 614
{0x0C06, 0x0C01, 0x0C05}, // preset 2; 615
{0x0C06, 0x0C01, 0x0C07}, // preset 2; 617
{0x0C06, 0x0C02, 0x0C00}, // preset 2; 620
{0x0C06, 0x0C02, 0x0C03}, // preset 2; 623
};
void setup()
{
// serial for debugging purposes
Serial.begin(57600);
// Set Switch pin as Input
pinMode(switchPin, INPUT_PULLUP);
// just a message to show that the arduino is ready
sendIRCommand();
}
void loop()
{
// variable to remember the last button state; initialised to NOT ISPRESSED
static int lastButtonState = !ISPRESSED;
// read the pin
int buttonState = digitalRead(switchPin);
// if the button changed from RELEASED to PRESSED or the other way around
if (buttonState != lastButtonState)
{
// remember the change
lastButtonState = buttonState;
if (buttonState == ISPRESSED)
{
if (buttonState == ISPRESSED)
{
// increment the preset
selectedPreset++;
// if we've reached the end of the presets, reset counter
if (selectedPreset == NUMPRESETS)
{
selectedPreset = 0;
}
// send the IR code(s)
sendIRCommand();
}
}
}
// simple debounce delay
delay(50);
}
/*
send IR code to receiver
*/
void sendIRCommand()
{
Serial.print("Sending preset ");
Serial.println(selectedPreset + 1);
for (int cnt = 0; cnt < MAXDIGITS; cnt++)
{
if (presets[selectedPreset][cnt] != 0x0000)
{
Serial.print(presets[selectedPreset][cnt], HEX);
Serial.print(" ");
delay(500);
}
}
Serial.println();
}
I hope I'm not being to annoying. I've never attempted anything like this before and am learning a great deal with your help.
Thanks again.