Single fade out after button press


this first program please, gentle, goal set code once press button, glows @ full brightness, fades out after let go, test code until feel confident enough move on real project, wire arduino uno sound system of car set of led lights pulse along bass of music, plan use same basic principle code, replace button input parallel line running subwoofers electrical impulse sets off arduino lighting leds bass hits light leds , fade off smoothly, if have input on fantastic, i'll post have far, in honesty copy , paste scrap book reference section of website. right code, arduino fades continuously high low when button not pressed , glows solid when pressed, offer immensly appreciated!
code: [select]
const int buttonpin = 2;
const int ledpin = 9;
int buttonstate = 0;
int led = 9;
int brightness = 0;
int fadeamount = 5;
void setup() {
  pinmode(ledpin, output);
  pinmode(buttonpin, input);
}
void loop() {
  buttonstate = digitalread(buttonpin);
  if (buttonstate == high) {
     digitalwrite(ledpin, high);
  }
  else {
     analogwrite(led, brightness);
     brightness = brightness - fadeamount;
     if (brightness == 0) {
      fadeamount = -fadeamount ;
}
delay(10);
  }
}

how switch wired?
it looks me input pin floating.


Arduino Forum > Using Arduino > Programming Questions > Single fade out after button press


arduino

Comments

Popular posts from this blog

Rasperry Wifi LAN Controller - Raspberry Pi Forums

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

Unlock car with bluetooth and car key