First, if the admins think this is too closely related to my "general" question in the other section, please take appropriate corrective actions.
I have a few specific programming questions so I figured I would post here for some help.
I am using a 2n2222 transistor to switch a laser circuit on/off. The first sketch I have posted worked just like I thought it would. From previous suggestions, I know the delay function is not ideal, but I wanted an obvious indicator if I could get the desired response.
I have laser1 wired to the 2n2222 base (through a resistor).
Nope! With the following sketch, the laser was always on - regardless of PB condition. I will say I was measuring the voltage at the pbeasy pin and it was measuring correctly (0V or 5V) when the PB was pressed/released.
Here is the sketch.
Thanks
I have a few specific programming questions so I figured I would post here for some help.
I am using a 2n2222 transistor to switch a laser circuit on/off. The first sketch I have posted worked just like I thought it would. From previous suggestions, I know the delay function is not ideal, but I wanted an obvious indicator if I could get the desired response.
I have laser1 wired to the 2n2222 base (through a resistor).
Feeling quite confident at this point, I then attempted to use a PB to turn the laser on and off. I am still getting my head around when an input pin is high/low, but I figured I could get the laser to turn off and on based on if I held the button down. My thinking was the laser would either be on at start up and turn off when I held the button down or it would be the other way around.//Laser Maze Program
//Assign laser units to pins
const int laser1 = 22;
void setup()
{
pinMode(laser1, OUTPUT);
}
void loop()
{
digitalWrite(laser1, HIGH);
delay(5000);
digitalWrite(laser1, LOW);
delay(5000);
}
Nope! With the following sketch, the laser was always on - regardless of PB condition. I will say I was measuring the voltage at the pbeasy pin and it was measuring correctly (0V or 5V) when the PB was pressed/released.
Here is the sketch.
So, any obvious mistakes on why laser1 wouldn't play nice with pbeasy? Small disclaimer: I am about 1 week into learning how to program so go easy and talk slow.//Laser Maze Program
//Assign laser units to pins
const int laser1 = 22;
const int pbeasy = 51;
void setup()
{
pinMode(laser1, OUTPUT);
pinMode(pbeasy, INPUT);
}
void loop()
{
if (pbeasy == LOW)
digitalWrite(laser1, HIGH);
else
digitalWrite(laser1, LOW);
}
Thanks