Hi. I'm wondering why my led's arn't working again. I have a button hooked up to pin 3, and pins on the leds to 4, 5, and 6. What I want to do is when the button is pushed, it will flash pin 6 2 times. Pins 4 and 5 switch between each other. Here's my code:
//int hit = 3; // the number of the pushbutton pin
int buttonState = 0; // variable for reading the pushbutton status
int delay1 = 200;
void setup() {
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(3, INPUT);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
//digitalWrite(4, HIGH);
//digitalWrite(buttonState, LOW); //enable internal pullup resister
}
void loop(){
buttonState = digitalRead(3);
if (buttonState == HIGH) {
digitalWrite(6, LOW);
}
else {
digitalWrite(6, HIGH);
b();
g();
}
}
void b(){
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
delay(delay1);
}
void g(){
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(delay1);
}
post your schematic, lets see what you have wired up.
You have nothing debouncing your button push, I would start with that.
Then add a "for x = 1 to 6" loop to write that pin hi/low 6 times with some delay after the change so you can see it.
No. There's 3 RGB led's, and there each hooked to each other. The + pin on each led has a 330ohm resister tied to 5V. The other ends go into pins 4 5 and 6. The button hasone side on ground, and the other with a 330ohm resister to pin 3. I downloaded the program you said, and I don't get it. Not that easy for me. There's no RGB led in the components manager.
Exacaly. I tried transisters, but they act funny when anyone is around them. If you get to close, the trigger... Stuipd transister. Now I'm trying a laser and it turned out to be a variable laser... XD whoops
Okay the resistor on the switch is doing nothing for you.
Remove, and add this this to void setup()
digitalWrite (3, HIGH);
that will turn on your internal pullup resistor and give you a High reading when the button is not pushed.
Right now , your input is floating.
It works, but just not how I want it to. What it does, is when the button is pressed, depending which color is on depends on how long it will take before red goes on. What I'd like it todo is when the button is pressed, it will add one to a variable and automatically switch it to red.
Well, now that your hardware is working, you can go back to fixing the code.
Until you get the button debounced, its kind of random what will happen in the loop when it is pressed. Start with that.
If you define the pins 4,5,6, as red-blue-green or whatever, it would probably make writing a color choice possilble.
We'll I don't know how much current my laser is that I'm using. My friend hacked it and gave it to me. It's 3V though, and to be safe, I run it with the transister. Problem is with the transister (any kind), when I get to close, it acts like the Arduino triggered it.
Sphere side forward, left pin is ground to the laser, middle pin is to a resister (330ohm to Arduino pin), and the right pin is Arduino ground and the other battery ground.