I know this is an old project, but hoping someone with more experience can help me. I'm pretty unga-bunga when it comes to programming.
My boss is actually responsible for the design of the US NES and Zapper, and I'm building him a sort of trophy for his career achievements. I thought it would be awesome to build an NES with lighting triggered by firing the zapper at it. I followed the guide but replaced the extension cord to the lamp with a 12v adapter running LED strip tape.
Thanks in advance!
EDIT: Figured it out! I ended up having to modify the script with support from my buddy. I was using this ATmega328P based Nano clone
The pinout is different so some things had to be adjusted. Will be posting my own project as a new thread when finished.
Lamp
#include <IRremote.h>
#include <Bounce2.h>
#define RELAY_PIN 12
#define BUTTON_PIN 10
#define RECV_PIN 11
Bounce button = Bounce(BUTTON_PIN, 10);
bool relayState = false;
IRrecv irrecv(RECV_PIN);
char lastChar;
void setup() {
Serial.begin(9600);
pinMode(RELAY_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
digitalWrite(RELAY_PIN, relayState);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
button.update();
if (button.fallingEdge()) {
relayState = !relayState;
digitalWrite(RELAY_PIN, relayState);
}
if (irrecv.decode()) {
char result = char(irrecv.decodedIRData.decodedRawData);
Serial.print(result);
if(result == 'P' && lastChar == 'Z') {
relayState = !relayState;
digitalWrite(RELAY_PIN, relayState);
}
irrecv.resume(); // Receive the next value
lastChar = result;
}
}
Zapper
Transmitter:
#include <IRremote.h>
#include <Bounce2.h>
#define triggerPin 2
IRsend irsend(9);
Bounce trigger = Bounce(triggerPin, 9);
void setup() {
pinMode(triggerPin, INPUT_PULLUP);
}
void loop() {
trigger.update();
if (trigger.fallingEdge()) {
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
irsend.sendRC5('Z', 12);
delay(20);
irsend.sendRC5('P', 12);
}
}