最迷你的Arduino開發板!約一元硬幣大小,價格約台幣90~150元(2022/1價格),適合輕度控制使用
1.支持Arduino IDE 1.0+ (OSX/Win/Linux)
2.能夠通過USB或者5v或者7-35v (自動匹配)額外電源供電
3.主機板上有500ma 5V調節器
4.USB嵌入(串口調試)
5.6個I/O Pins (2個用來支持USB)
6.8k Flash Memory (about 6k after bootloader)
7. I2C and SPI (vis USI)
8. PWM on 3 pins (more possible with Software PWM)
9. ADC on 4 pins
10.Power LED指示燈和Test/Status LED (在Pin0)
安裝Digispark(Attiny85)驅動程式並使用ARDUINO編譯
第一次使用Digispark(Attiny85)需要安裝USB驅動程式,跟使用ARDUINO編譯環境
1.下載Arduino IDE:至少使用1.6.6或更高版本
https://www.arduino.cc/en/Main/Software
2.下載USB驅動程式並安裝(安裝時接上Digispark(Attiny85)板子,讓USB驅動安裝)
https://github.com/digistump/DigistumpArduino/releases/download/1.6.7/Digistump.Drivers.zip
3.執行Arduino> File檔案> Preference偏好設定
4.在Additional Boards Manager URLs額外的開發板管理員網址欄位輸入:
http://digistump.com/package_digistump_index.json
5.在 Tool工具 >Board開發板 選取Board Manager開發板管理員 並在TYPE類型 選取Contributed貢獻,搜尋Digispark 選擇Digistump AVR Boards並安裝install
6.設定好對應電路板16.5mhz:Digispark(Default 16.5mhz)
7.輸入以下測試程式碼,檢查LED能否正常閃爍
void setup() {
pinMode(1, OUTPUT); //LED on Model A
}
void loop() {
digitalWrite(1, HIGH);// turn the LED on
delay(1000); // wait for a second
digitalWrite(1, LOW); // turn the LED off
delay(1000); // wait for a second
}
8.拔掉Attiny85電路板,按上傳程式碼執行後,出現如下二行提示請接上電路板時再接上,完成燒錄
Running Digispark Uploader...
Plug in device now... (will timeout in 60 seconds)
9.本次燈板使用內建範例程式,需設定Pin腳位及修改燈數24
#define PIN 0
Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);
20220120多層燈板底座(10.1mm)設計圖(dxf下載)
底座大小長145x寬45x高30,邊厚2.5(mm)
外框擠出30,內框移除21
頂面繪制草圖開槽130X5,間距10.6(mm)
燈板設計參考用素材 PNPTREE
WS2812B可程式控制LED使用Adafruit NeoPixel函式庫Adafruit_NeoPixel.h,函式詳細說明<連結GiHub>
#include <Adafruit_NeoPixel.h> //引入函式
Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
//創建函式並命名,可以隨意命名,也可設定多個,此範例中為"strip";並設定 參數1 NUMPIXELS:燈數 參數2 PIN:引腳 參數3 NEO_GRB + NEO_KHZ800:LED型式
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
strip.begin();
strip.clear();
strip.show();
strip.show(); // Initialize all pixels to 'off'
begin() //初始化燈條
updateLength() //更新燈數
updateType() //更新LED型號
show() //輸出,所有設定需執行此函數才能執行
delay_ns() //
setPin() //設定引腳
setPixelColor() //設定RGB參數
fill()
ColorHSV()
getPixelColor() //取得目前RGB參數
setBrightness() //設定整體亮度
getBrightness() //取得整體亮度
clear() //清除所有設定,將顏色的R、G、B設定爲0
gamma32()
//目標:設定第一顆燈的顏色、明滅example01
#include <Adafruit_NeoPixel.h> //引用NeoPixel的函式庫
#define PIN 0 //宣告PIN為腳位0 (Attiny的腳位0接燈條)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);
//宣告一個名為strip的燈條,參數(24顆燈,腳位為PIN,燈條晶片類型為NEO_GRB + NEO_KHZ800)
void setup() {
strip.begin(); //初始化燈條
strip.show(); //更新現在燈條狀態
}
void loop() {
strip.setPixelColor(0, strip.Color(255, 0, 0));
//設定燈珠顏色,參數(第0+1顆燈,顏色為strip.Color(255, 0, 0))
//strip.Color(R, G, B); 設定顏色,參數為(紅、綠、藍)各色光的亮度,範圍0-255
strip.show();//更新現在燈條狀態
delay(3000);
strip.setPixelColor(0, strip.Color(0, 0, 0));
strip.show();//更新現在燈條狀態
delay(3000);
}
//依序點亮紅、綠、藍,然後一起熄滅example01_1
#include <Adafruit_NeoPixel.h>
#define PIN 0
Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show();
}
void loop() {
strip.setPixelColor(0, strip.Color(255, 0, 0));
strip.show();
delay(1000);
strip.setPixelColor(1, strip.Color(0, 255, 0));
strip.show();
delay(1000);
strip.setPixelColor(2, strip.Color(0, 0, 255));
strip.show();
delay(1000);
strip.setPixelColor(0, strip.Color(0, 0, 0));
strip.setPixelColor(1, strip.Color(0, 0, 0));
strip.setPixelColor(2, strip.Color(0, 0, 0));
strip.show();
delay(3000);
}
//依序點亮每顆燈、依序熄滅(使用for 迴圈)example02
#include <Adafruit_NeoPixel.h>
#define PIN 0
Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show();
}
void loop() {
//for迴圈,參數(起始值,運作條件,更新值)
//for(int i =0;i < 10;i++) i從0數到9
//運作方式:以i為變數,判斷是否滿足運作條件 > 執行迴圈內容 > i遞增 > 再判斷 > 用新的i執行迴圈內容
//逐顆點亮LED
for(int i = 0; i <strip.numPixels(); i++) {
strip.setPixelColor( i , strip.Color(0, 0, 255));
strip.show();
delay(50);
}
//逐顆熄滅LED
for( int i = 0; i <strip.numPixels(); i++) {
strip.setPixelColor( i , strip.Color(0, 0, 0));
strip.show();
delay(50);
}
delay(500);
}
//奇數顆燈亮紅色、偶數顆燈亮藍色example03
#include <Adafruit_NeoPixel.h>
#define PIN 0
Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show();
}
void loop() {
//奇數顆設定藍色
for (int i=0; i < strip.numPixels(); i=i+2) {
strip.setPixelColor(i, strip.Color( 0, 0, 255));
}
strip.show(); //更新燈條狀態
delay(50);//間隔時間
//奇數顆設定熄滅
for (int i=0; i < strip.numPixels(); i=i+2) {
strip.setPixelColor(i, strip.Color( 0, 0, 0));
}
strip.show();//更新燈條狀態
delay(50);
//偶數顆設定藍色
for (int i=1; i < strip.numPixels(); i=i+2) {
strip.setPixelColor(i, strip.Color( 0, 0, 255));
}
strip.show();
delay(50);
//偶數顆設定熄滅
for (int i=1; i < strip.numPixels(); i=i+2) {
strip.setPixelColor(i, strip.Color( 0, 0, 0));
}
strip.show();
delay(50);
}
//呼吸燈example04
#include <Adafruit_NeoPixel.h>
#define PIN 0
Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show();
}
void loop() {
//漸亮
//雙層for迴圈,內層為設定每顆燈,外層為欲調整的亮度值
for( int j = 0; j<200 ; j+=3){
for(int i = 0; i <strip.numPixels(); i++) {
strip.setPixelColor( i , strip.Color(0, 0, j));
}
strip.show();//待每顆顆燈設定好之後再全部一起更新狀態
delay(50);
}
//漸暗
for( int j = 200; j>0 ; j-=3){
for(int i = 0; i <strip.numPixels(); i++) {
strip.setPixelColor( i , strip.Color(0, 0, j));
}
strip.show();
delay(50);
}
}
//彩虹變色example05
#include <Adafruit_NeoPixel.h>
#define PIN 0
Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show();
}
void loop() {
//紅色漸暗,綠色漸亮
//雙層for迴圈,內層為設定每顆燈,外層為欲調整的亮度值
for( int j = 0; j<255 ; j++){
for(int i = 0; i <strip.numPixels(); i++) {
strip.setPixelColor( i , strip.Color(255-j, j, 0));
}
strip.show();//待每顆顆燈設定好之後再全部一起更新狀態
delay(50);
}
//綠色漸暗,藍色漸亮
for( int j = 0; j<255 ; j++){
for(int i = 0; i <strip.numPixels(); i++) {
strip.setPixelColor( i , strip.Color(0, 255-j, j));
}
strip.show();
delay(50);
}
//藍色漸暗,紅色漸亮
for( int j = 0; j<255 ; j++){
for(int i = 0; i <strip.numPixels(); i++) {
strip.setPixelColor( i , strip.Color(j, 0, 255-j));
}
strip.show();
delay(50);
}
}
//每隔三顆為一組,三組依序亮滅(彩虹變色)。example05_2
#include <Adafruit_NeoPixel.h>
#define PIN 3
Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);
//紅色漸暗,綠色漸亮
uint32_t RtoG(byte k) {
return strip.Color(255 - k*3, k*3, 0);
}
//綠色漸暗,藍色漸亮
uint32_t GtoB(byte k) {
return strip.Color(0, 255 - k*3, k*3);
}
//藍色漸暗,紅色漸亮
uint32_t BtoR(byte k) {
return strip.Color(k*3, 0, 255 - k*3);
}
void setup() {
strip.begin();
strip.show();
}
void loop() {
//紅色漸暗,綠色漸亮
for( int k = 0;k<85;k++){
//因為有三組,使用j=0、j=1、j=2,各設定一次
for(int j=0; j < 3; j++) {
//每個三顆燈設定一次,從RtoG取色
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+j, RtoG(k));
}
strip.show();
delay(50);
//每隔三顆燈設定一次,熄滅
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+j, 0);
}
strip.show();
delay(50);
}
}
//綠色漸暗,藍色漸亮
for( int k = 0;k<85;k++){
//因為有三組,使用j=0、j=1、j=2,各設定一次
for(int j=0; j < 3; j++) {
//每個三顆燈設定一次,從GtoB取色
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+j, GtoB(k));
}
strip.show();
delay(50);
//每隔三顆燈設定一次,熄滅
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+j, 0);
}
strip.show();
delay(50);
}
}
//藍色漸暗,紅色漸亮
for( int k = 0;k<85;k++){
//因為有三組,使用j=0、j=1、j=2,各設定一次
for(int j=0; j < 3; j++) {
//每個三顆燈設定一次,從BtoR取色
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+j, BtoR(k));
}
strip.show();
delay(50);
//每隔三顆燈設定一次,熄滅
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+j, 0);
}
strip.show();
delay(50);
}
}
}
rainbowCycle
#include <Adafruit_NeoPixel.h>
#define PIN 0
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(27, PIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
randomSeed(analogRead(A1));
int i = random(0,100);
Serial.println(i);
if(i>50)
{
strip.setBrightness(30);
}
}
void loop() {
if(strip.getBrightness()<50){
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue
rainbow(80);
}
rainbowCycle(20);
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, c); //turn every third pixel on
}
strip.show();
delay(wait);
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
strip.show();
delay(wait);
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
}