顯示具有 LED 標籤的文章。 顯示所有文章
顯示具有 LED 標籤的文章。 顯示所有文章

2018年12月17日

led偵測光線

當我看到micro:bit使用25顆LED當光線偵測工具時,真的佩服其想法。也想證實一下。
我使用bpi-bit,在P0接上紅線,GND接上黑線,另一端接上2顆紅色LED燈。

使用arduino ide來偵測程式碼如下:
void setup() {
 Serial.begin(115200); //Serial Port Config 115200-8-N-1
}
void loop() {
  Serial.println(analogRead(P0));
    delay(500);
}

程式很簡單只有顯示P0的類比訊號值。

2018年10月8日

bpi-bit LED 數位亮燈

arduino ide 實作led亮燈

開一個arduino新檔,板子選擇bpi-bit(板子設定方法請參考https://wdpsestea.blogspot.com/2018/10/bpi-bit-arduino-ide.html ,ubuntu使用者參考https://wdpsestea.blogspot.com/2018/09/bpi-bit-arduino-ide.html ) 選擇連擁port(win下是comX,linux下是ttyUSBX),燒錄速度建議降低些。




void setup() {
  // put your setup code here, to run once:

}
前include下列檔案
我們有25個LED和使用PixelPin 4來溝通。

#include <Arduino.h>
#include <NeoPixelBus.h>
#include "WiFi.h"
//WS2812 config
const uint16_t PixelCount = 25;
const uint8_t PixelPin = 4;
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);


#define colorSaturation 32
//定義WS2812 腳位 2
#define ledPower 2
//定義顏色
RgbColor red(colorSaturation, 0, 0);
RgbColor green(0, colorSaturation, 0);
RgbColor blue(0, 0, colorSaturation);
RgbColor white(colorSaturation);
RgbColor black(0);
HslColor hslRed(red);
HslColor hslGreen(green);
HslColor hslBlue(blue);
HslColor hslWhite(white);
HslColor hslBlack(black);


void setup() {
  // put your setup code here, to run once:

}
中加入
  Serial.begin(115200); //Serial Port Config 115200-8-N-1
  while (!Serial); // wait for serial attach

  Serial.println();
  Serial.println("Initializing...");
  Serial.flush();

  // this resets all the neopixels to an off state
  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(0, red);
            strip.Show();
            delay(100);
            strip.SetPixelColor(0, black);
            strip.Show();
            delay(100);
亮燈,strip.SetPixelColor(0, red);0是第幾個燈按照下圖排列,顏色則按RgbColor定義的內容

 要熄滅則用黑色
strip.SetPixelColor(0, black);
間隔時間使用delay(微秒),1秒=1000微秒。
 delay(1000);


2015年11月15日

電光超人

心中突然有個想法,來做個電影版的電光超人,應該做得起來。展場上應該很有效果。
材料:motuduino、LED燈條、s4a sencerboard、鋰電池
5米的LED燈條是要接110V的電到變壓器中轉成12V 2A的電出來,而motoduino的版子可以撐到12V,這樣就好玩了。
於是把這些組合起來。
首先把LED的電源改成motoduino供電,走pin 6 pwm(馬達腳位),但motoduino的版子只有5V供電,所以要外接電源。接起來就變成這樣了。

使用arduino ide+ AdruBlock把程式寫入板子(加上s4a的sencer board可以做互動),就變成可以到處移動的電光超人了。