Ok so i have come up with a way that works and does what i want.
Here's what i made so far:
Code: Select all
// Constants won't change. They're used here to set pin numbers:
const int irPin = 3; // The number of the ir pin
const int soundPin = 4; // The number of the sound trigger pin
const int motorPin = 5; // The number of the motor trigger pin
const int powerPin = 2; // The number of the power pin / trigger
void setup()
{
pinMode(soundPin, OUTPUT); // Initialize the Sound pin as an output
pinMode(motorPin, OUTPUT); // Initialize the Motor pin as an output
pinMode(buttonPin, INPUT); // Initialize the pushbutton pin as an input
pinMode(powerPin, OUTPUT); // Initialize the power pin as an output
digitalWrite(powerPin, HIGH); // Turns on power loop
digitalWrite(soundPin, LOW); // Turn off Sound trigger
}
void loop()
{
digitalWrite(soundPin, HIGH); // Triggers Sound to play
delay(100); // Wait for the soundboard to register a signal
digitalWrite(soundPin, LOW); // Turn off Sound trigger
delay(100); // Delays the Motor for timing with the sound
digitalWrite(motorPin, HIGH); // Turn Motor on
delay(1000); // Runs the motor for 1 second
digitalWrite(motorPin, LOW); // Turn Motor off
delay(1500); // Wait for the sound to finnish playing
digitalWrite(powerPin, LOW); // Turns off power loop
}
Now i need to figure out how the ir thing work.
This is the code for the zapper that wermy provided.
Code: Select all
#include <IRremote.h>
#include <Bounce2.h>
#define triggerPin 2
IRsend irsend;
Bounce trigger = Bounce(triggerPin, 10);
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);
}
}
From what i have learnd so far i have no clue how this works.
I have conected it exaktly as in the video but i get no response when i try it out. I used the same pins and made sure they had the same functions as the ones wermy used.
Am i right that i should see the ir diod flash when lookong through a camera?
If i look at the code i see "
#define triggerPin 2" I have my trigger on pin 2 as well.
Then i see "
bounce" witch i dont know what it is at the moment. It seems to refer to pin 10 witch wasn't mensiond in the video.
Then i see"
digitalWrite(13,
HIGH);" Pin 13 is the built in led on my Arduino Micro. I guess that this is intended to show something being sent on the ir diod with visual light on the built in led.
Lastly i see " irsend.
sendRC5('
Z', 12);" witch seems to refer to pin 12 witch also wasn't mensiond in the video.
Could someone help me understand this code?