ไลบรารี Blinker สำหรับแพลตฟอร์ม Arduino
ใหม่: ห้องสมุดนี้รองรับไฟ LED Neopixel
ห้องสมุดนี้ช่วยให้คุณสามารถดำเนินการกะพริบด้วย LED เนื่องจากมันทำงานกับ Neopixels จึงขึ้นอยู่กับไลบรารี Adafruit_neopixel ดังนั้นคุณต้องติดตั้งในสภาพแวดล้อมของคุณเพื่อให้มันรวบรวม
ห้องสมุดมีสามคลาส:
คลาสนี้ช่วยให้คุณกะพริบ LED
คลาสนี้ช่วยให้คุณกะพริบ Neopixel
คลาสนี้ช่วยให้คุณสร้างวัตถุสีสำหรับคลาส PixelBlinker
คลาส LedBlinker ช่วยให้คุณสร้างอินสแตนซ์ของ LED ที่คุณต้องการใช้งาน ตัวสร้างคลาสใช้สองค่าเป็นอาร์กิวเมนต์ อาร์กิวเมนต์แรก คือพินที่เชื่อมต่อ LED อาร์กิวเมนต์ที่สอง เป็น ทางเลือก ในการกำหนดขั้วของ LED หากอาร์กิวเมนต์นี้ไม่ได้ให้ขั้ว LED จะถูกตั้งค่าเป็นค่าลบทั่วไปโดยค่าเริ่มต้น
/* LedBlinker Instance.
* First argument: The pin where the LED is connected.
* Second argument: Optional argument to define the LED polarity.
Allowed values:
COMMON_NEGATIVE
COMMON_POSITIVE
*/
LedBlinker myBlueLed ( 13 , COMMON_POSITIVE); /* Set the pin where the LED is connected. */
myBlueLed.setPin(pin); /* Set the LED polarity.
* Allowed values: COMMON_NEGATIVE, COMMON_POSITIVE.
*/
myBlueLed.setPolarity(COMMON_NEGATIVE); /* Turn On the LED. */
myBlueLed.on(); /* Turn Off the LED. */
myBlueLed.off(); /* Turn On the LED for the time of "onDuration" then call the "onFinished" method. */
myBlueLed.onUntil(onDuration, onFinished); /* Turn Off the LED for the time of "offDuration" then call the "onFinished" method. */
myBlueLed.offUntil(offDuration, onFinished); /* Blink the LED.
* The LED will be On for the time of "onDuration".
* The LED will be Off for the time of "offDuration".
* That blink will be repeated the number of times defined by "blinks".
* Then a pause define by "pauseDuration".
* That sequency will repeat as many time as defined by "sequences".
* At the end of all sequences the "onFinished" method will be called.
*/
myBlueLed.blink(onDuration, offDuration, blinks, pauseDuration, sequences, onFinished); /* Allways call this method in the loop. */
myBlueLed.update();คลาส PixelBlinker อนุญาตให้คุณสร้างอินสแตนซ์ของ neopixel ที่คุณต้องการใช้งาน ตัวสร้างคลาสใช้ค่าสามค่าเป็นอาร์กิวเมนต์ อาร์กิวเมนต์แรก คือพินที่เชื่อมต่อ neopixel อาร์กิวเมนต์ที่สอง คือจำนวนของ neopixel ที่เชื่อมต่อกัน อาร์กิวเมนต์ที่สาม เป็น ทางเลือก ในการกำหนดประเภทของ neopixel
/* PixelBlinker Instance.
* First argument: The number of the pin where the NeoPixel is connected.
* Second argument: The amount of NeoPixel connected together.
* Third argument: Optional argument to define the NeoPixel type.
Pixel types:
NEO_GRB + NEO_KHZ800
NEO_GRB + NEO_KHZ400
NEO_RGB + NEO_KHZ800
NEO_RGB + NEO_KHZ400
If this argument is not provided the NeoPixel type will be set to NEO_GRB + NEO_KHZ800 by default.
*/
PixelBlinker myNeoPixel (pixelPin, pixels, NEO_GRB + NEO_KHZ800); /* Set the pin where the NeoPixel is connected. */
myNeoPixel.setPin(pin); /* Set the amount of Pixel connected. */
myNeoPixel.setNumPixels(numPixels); /* Set the Pixel that you want to operate. */
myNeoPixel.setPixel(pixelId); /* Set the color of the Pixel. The argument must be a PixelColor object. */
myNeoPixel.setPixelColor(pixelColor); /* Set the Pixel brightness, 0 - 255 value. */
myNeoPixel.setPixelBrightness(pixelBrightness); /* Set the Pixel brightness using percentage. */
myNeoPixel.setPixelBrightnessPercent(pixelBrightnessPercent); /* Turn On the Pixel. */
myNeoPixel.on(); /* Turn On the Pixel by it's Id. */
myNeoPixel.on(pixelId); /* Turn Off the Pixel. */
myNeoPixel.off(); /* Turn Off the Pixel by it's Id. */
myNeoPixel.off(pixelId); /* Turn On the Pixel for the time of "onDuration" then call the "onFinished" method. */
myNeoPixel.onUntil(onDuration, onFinished); /* Turn On the Pixel by it's Id, for the time of "onDuration" then call the "onFinished" method. */
myNeoPixel.onUntil(pixelId, onDuration, onFinished); /* Turn Off the Pixel for the time of "offDuration" then call the "onFinished" method. */
myNeoPixel.offUntil(offDuration, onFinished); /* Turn Off the Pixel by it's Id, for the time of "onDuration" then call the "onFinished" method. */
myNeoPixel.offUntil(pixelId, offDuration, onFinished); /* Blink the Pixel.
* Argument "onDuration": The time that the pixel will be On in the cycle.
* Argument "offDuration": The time that the pixel will be Off in the cycle.
* Argument "blinks": The number of times to blink the Pixel.
* Argument "pauseDuration": The time to wait between sequences.
* Argument "sequences": The number of times to repeat the sequence.
* Argument "onFinished": The function to call when finished.
*/
myNeoPixel.blink(onDuration, offDuration, blinks, pauseDuration, sequences, onFinished); /* It is always necessary to call this method in the loop. */
myNeoPixel.update();คลาส PixelColor ช่วยให้คุณสร้างวัตถุสีที่จะใช้กับคลาส PixelBlinker คุณอาจสร้างวัตถุสีได้มากเท่าที่คุณต้องการด้วยค่าสีที่กำหนดเอง
/* Red color object to be used by PixelBlinker */
PixelColor red ( 255 , 0 , 0 ); /* Green color object to be used by PixelBlinker */
PixelColor green ( 0 , 255 , 0 ); /* Blue color object to be used by PixelBlinker */
PixelColor blue ( 0 , 0 , 255 ); /* Custom color object to be used by PixelBlinker */
PixelColor myCustomColor ( 100 , 100 , 255 );การใช้งานปกติของคลาสนี้ไม่จำเป็นต้องใช้วิธีการใด ๆ เหล่านี้
/* Returns the red value of the color. */
myCustomColor.r(); /* Returns the green value of the color. */
myCustomColor.g(); /* Returns the blue value of the color. */
myCustomColor.b(); /* Returns the packed value of the color in RGB format. */
myCustomColor.getPackedRGB(); /* Returns the packed value of the color in GRB format. */
myCustomColor.getPackedGRB();mit © Evert Arias