hi everyone
im new to arduino
this is my code the aim of this is to remotely activate it
they leds flash and stop randomly, there are two colors
i just need to know what to write
const int buttonPin = 2; // Pin number for the button
const int led1Pin = 9; // Pin number for the first LED
const int led2Pin = 10; // Pin number for the second LED
bool isFlashing = false;
void setup() {
pinMode(buttonPin, INPUT_PULLUP); // Set button pin as input with internal pull-up resistor
pinMode(led1Pin, OUTPUT); // Set LED1 pin as output
pinMode(led2Pin, OUTPUT); // Set LED2 pin as output
Serial.begin(9600); // Initialize serial communication
}
void loop() {
// Check if the button is pressed
if (digitalRead(buttonPin) == LOW) {
// Wait for button release to avoid bouncing issues
while (digitalRead(buttonPin) == LOW) {}
// Start flashing LEDs
isFlashing = true;
// Seed the random generator
randomSeed(analogRead(A0));
// Flash LEDs alternately
while (isFlashing) {
digitalWrite(led1Pin, HIGH);
digitalWrite(led2Pin, LOW);
delay(100); // Adjust delay as needed
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, HIGH);
delay(100); // Adjust delay as needed
// Randomly decide whether to stop flashing
if (random(0, 100) < 5) { // 5% chance to stop each cycle
isFlashing = false;
// Randomly choose the LED to leave on
if (random(0, 2) == 0) {
digitalWrite(led1Pin, HIGH);
digitalWrite(led2Pin, LOW);
} else {
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, HIGH);
}
}
}
}
}
what im wanting to do is add code for an ir receiver to act as the button
the button can be left on
at present i cant get it to work
ir pins are
g- ground
v-5volt
s-pin 3
the program works fine with just button
i have managed to get the hex for button on remote i just dont know how to add the code for ir into this code
everything i look up says error wrong ir library stuff
im assuming its just outdated code pre 2019 or something
i used chatgpt to get this code but yeah cant get it to do succesful ir extra
thanks all