Hello! I have an adafruit-gemma and a arduino puchbuttom and wounder if someone will help me with a code if thats possible.
The whole thing is for lightning some rgb leds.
I want it to be 3 step on the buttom, when you press it one time it will just light up white
When you press it a second time it will flash and Third time it will go to off. Can someone help me whit this :)? I am a really beginner at this.
And sorry for my bad english
im basically where you are at.. this tut starts with basic button commands, im working on a midi controller and having some issues, watching this has helped a lot so far.
enum State {
 OFF, ON, FLASHING;
} state;
const int buttonPin = 3;
const int ledPin = 3;
const unsigned long flashTimeMs = 250;
int buttonState;
unsigned long flashMs;
booean flashState;
void setup() {
 pinMode(buttonPin, INPUT_PULLUP);
 pinMode(ledPin, OUTPUT);
 state = OFF;
 buttonState = digitalRead(buttonPin);
}
void loop() {
 int buttonStateNow = digitalRead(buttonPin);
 boolean buttonPressed = (buttonState=HIGH) && (buttonStateNow == LOW);
Â
 switch(state) {
 case OFF:
  if(buttonPressed) {
   digitalWrite(ledPin, HIGH);
   state = ON;
  }
  else {
   ; // do nothing
  }
  break;
 case ON:
  if(buttonPressed) {
   digitalWrite(ledPin, LOW);
   state = FLASHING;
   flashMs = millis();
   flashState = false;
  }
  else {
   ; // do nothing
  }
  break;
 case FLASHING:
  if(buttonPressed) {
   digitalWrite(ledPin, LOW);
   state = OFF;
  }
  else {
   flash_the_led();
  }
  break;
 }
 buttonState = buttonStateNow;
}
void flash_the_led() {
 if(millis() - flashMs < flashTimeMs) return;
 digitalWrite(ledPin, flashState = !flashState);
 flashTimeMs = millis();
}
SHHH your not supposed to give him the easy way out.. hes supposed to watch the hours of tutorials like the rest of us PaulS wouldnt help me with code.. just vague tips witch are not much help to a noob
Eriix:
No i have't look at any example codes. Where can i find them? Like i said, i'm a really beginner at this
Many programming examples are included in the Arduino-IDE and you can find them under the "File" menu option.
Programming example about a button reading the "HIGH" or "LOW" state:
File - Examples - Digital - Button
But what you want is to detect "when a button is pressed down", this is in technical speak a "state change detection". This example is to be found at:
File - Exemples - Digital - StateChangeDetection
RobTapps:
SHHH your not supposed to give him the easy way out.. hes supposed to watch the hours of tutorials like the rest of us PaulS wouldnt help me with code.. just vague tips witch are not much help to a noob
I do hope you're kidding. One thing we might agree about - I rarely get anything useful from videos. They're usually just a show-and-tell of some code and wiring that I could read about more effectively.
It's almost axiomatic in the learning business that you have to do some things yourself or you won't learn. In computing, information gathering is an important skill. To do it effectively, you have to take control and not just let Google steer you to some crappy wanna be demos on YouTube.
I have been ramping up on Arduino for about 2-3 months now. I find videos useless, but built in examples are good to build on and pretty well documented. (File>examples) I express caution, getting libs outside of the core libs that come with Arduino 1.x and newer. Usually causes more problems than is worth it for the starter. Save those for the experienced. Unlike other boards, the Arduino forum, can be a hostile place, where arrogance reigns and code samples are sparse. I have received good support from the forum, once they understood, I didn't have a clue....