|
|
本帖最后由 hsr18299 于 2015-2-20 13:55 编辑
農曆年去哪都人擠人,在家玩玩Arduino也是很好的娛樂!!
先來段視頻,有興趣再往下看,不浪費大家的時間!!
仿指針時鐘
外圈用4個Adafruit NeoPixel 1/4 60 Ring - WS2812 5050 RGB LED w/ Integrated Drivers 模擬分針跟秒針
內圈用1個Adafruit NeoPixel Ring - 24 x WS2812 5050 RGB LED with Integrated Drivers 模擬時針移動
可畫上自己喜歡的面板
sketch用上兩個庫DS1307及FastLED,一併附上
sketch如下
- #include <Wire.h>
- #include <Time.h>
- #include <DS1307RTC.h>
- #include <FastSPI_LED2.h>
- #define NUM_LEDS1 60
- #define NUM_LEDS2 24
- #define DATA_PIN1 7
- #define DATA_PIN2 9
- int idex = 0;
- int idexs = 0;
- int idexm = 0;
- int idexh = 0;
- int ihue = 0;
- int isat = 0;
- int ibright = 0;
- CRGB smleds[NUM_LEDS1];
- CRGB hleds[NUM_LEDS2];
- void setup() {
- FastLED.addLeds<WS2812B, DATA_PIN1, RGB>(smleds, NUM_LEDS1);
- FastLED.addLeds<WS2812B, DATA_PIN2, RGB>(hleds, NUM_LEDS2);
- }
- void loop() {
- tmElements_t tm;
- RTC.read(tm);
-
- idexs = tm.Second;
- idexm = tm.Minute;
- idexh = tm.Hour;
-
- smleds[idexm] = CHSV(95, 255, 192);
- LEDS.show();
-
- smleds[idexs] = CHSV(2, 198, 128);
- LEDS.show();
-
- if (idexh >12 ) { idexh -= 12;}
-
- if (idexm <= 29) {
- long m = map (idexm, 0,29,0,255);
- hleds[idexh*2] = CHSV(164, 255, 255-m);
- hleds[(idexh*2)+1] = CHSV(164, 255, m);
- if (idexh == 12) {
- hleds[0] = CHSV(164, 255, 255-m);
- hleds[1] = CHSV(164, 255, m);}}
- else {
- long m = map (idexm, 30,59,0,255);
- hleds[(idexh*2)+1] = CHSV(164, 255, 255-m);
- hleds[(idexh+1)*2] = CHSV(164, 255, m);
- if ((idexh+1)*2 == 24) {
- hleds[0] = CHSV(164, 255, m); }
- if (idexh == 12) {
- hleds[1] = CHSV(164, 255, 255-m);
- hleds[2] = CHSV(164, 255, m);}}
- LEDS.show();
- delay(1000);
- LEDS.clear();
- }
复制代码
接線部分應該不用多說了(我承認是我太懶了)
祝大家新年快樂!!
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|