2018年10月12日

bpi-bit led function

要讓led亮燈程式碼
#include <NeoPixelBus.h>
const uint16_t PixelCount = 25;
const uint8_t PixelPin = 4;
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);


#define colorSaturation 128
#define ledPower 2

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200); //Serial Port Config 115200-8-N-1
  strip.Begin();
  strip.Show();
  pinMode(ledPower,OUTPUT);
  digitalWrite(ledPower, HIGH); //It's very important for the v1.2, if you use the v1.4 ,you can delete it

}

void loop() {
  // put your main code here, to run repeatedly:
  strip.SetPixelColor(20, RgbColor (0, 255, 0));
  strip.Show();
  delay(100);
  strip.SetPixelColor(20, RgbColor (0, 0, 0));
  strip.Show();
  delay(100);

}


把led燈滅用副程式來做:在void setup(){}前加入
 void led_black(){
  int i =0 ;
  for ( i =0;i <25;i++){
    strip.SetPixelColor(i, RgbColor (0, 0, 0));
    }
    strip.Show();
}
再把
  strip.SetPixelColor(20, RgbColor (0, 0, 0));
  strip.Show();
兩行改成呼叫副程式一行,以後只要一個副程式即可以把led燈熄滅。
   led_black();




沒有留言: