Stránka 1 z 1

neopixel button

Napsal: 17 lis 2019, 21:10
od Sniper
Ahojte. Som nováčik s arduino a potreboval by som pomôcť s projektom.. Potreboval by som dostať 2 tlačitka do projektu tak aby som tlačítkom1 spustil case1 a tlačítkom2 case 2..

Tu je projekt ale zatial funguje s jedným tlačítkom..

Kód: Vybrat vše

#include <Adafruit_NeoPixel.h>

#define BUTTON_PIN   2   
#define PIXEL_PIN    9   
#define PIXEL_COUNT 34 
int brightness = 255;  

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);

bool oldState = HIGH;
int showType = 0;

void setup() {
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  strip.begin();
  strip.setBrightness(brightness);
  strip.show();
}

void loop() {
  bool newState = digitalRead(BUTTON_PIN);
  if (newState == LOW && oldState == HIGH) {
    delay(20);
    newState = digitalRead(BUTTON_PIN);
    if (newState == LOW) {
      showType++;
      if (showType > 2)
        showType=0;
      startShow(showType);
    }
  }
  oldState = newState;
}

void startShow(int i) {
  switch(i){
    case 0: colorWipe(strip.Color(0, 0, 0), 40);
            break;
    case 1: colorWipe(strip.Color(225, 255, 255), 40);
            break;
    case 2: colorWipe(strip.Color(255, 0, 0), 40);
            break;

  }
}
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<(strip.numPixels()/2); i++) {
    strip.setPixelColor((strip.numPixels()/2-1)-i, c);
    strip.setPixelColor((((strip.numPixels()/2)+i)), c);
    strip.show();
    delay(wait);
  } 
}

Re: neopixel button

Napsal: 18 lis 2019, 02:20
od kiRRow
No nejprve program rozšíříš o ošetření druhého tlačítka. Potom budeš po stisku jednoho volat startShow(1); a po stisku druhého startShow(2);. Vypnutí provedeš zavoláním startShow(0);

Re: neopixel button

Napsal: 18 lis 2019, 13:35
od Sniper
dakujem a mohol by si mi poslat jak by mal vypadat ten kod cely?

Re: neopixel button

Napsal: 18 lis 2019, 15:16
od gilhad

Re: neopixel button

Napsal: 20 lis 2019, 20:25
od Sniper
tak nic teda.. dakujem za pomoc :|