2016年4月7日 星期四
2016年4月6日 星期三
LM35溫度感測器
紅色(5v)/黑色(接地)/綠色(A0)
程式
int potPin = A0 ;//接收腳A0
void setup()
{
Serial.begin(9600);
}
void loop()
{
int val;
int dat;
val = analogRead(potPin);//讀取
dat = (125*val)>>8 ;//轉換成溫度
// Serial.print("Tep : ") ;
Serial.println(dat) ;
// Serial.println("C");
delay(500);
}
從工具/打開序列埠監視窗,就可以看到溫度的顯示,也可從serial plotter匯出圖形
程式
int potPin = A0 ;//接收腳A0
void setup()
{
Serial.begin(9600);
}
void loop()
{
int val;
int dat;
val = analogRead(potPin);//讀取
dat = (125*val)>>8 ;//轉換成溫度
// Serial.print("Tep : ") ;
Serial.println(dat) ;
// Serial.println("C");
delay(500);
}
從工具/打開序列埠監視窗,就可以看到溫度的顯示,也可從serial plotter匯出圖形
RGB2
網路上找到的聰明代碼,就不用那麼累了。
使用三色全彩LED製造
模組有3個輸出
1. R,紅色輸出,
2. G,綠色輸出,
3. B,藍色輸出.
3組信號輸出,可通過單片機程式設計實現R,G,B三種顏色的混合達到全彩的效果,
實驗代碼:
int ledPin = 13; //
LED is connected to digital pin 13
int redPin = 11; // R petal on RGB LED module connected to
digital pin 11
int greenPin = 9; // G petal on RGB LED module connected to
digital pin 9
int bluePin = 10; // B petal on RGB LED module connected to
digital pin 10
void setup()
{
pinMode(ledPin, OUTPUT); // sets the
ledPin to be an output
pinMode(redPin, OUTPUT); // sets the
redPin to be an output
pinMode(greenPin, OUTPUT); // sets the
greenPin to be an output
pinMode(bluePin, OUTPUT); // sets the
bluePin to be an output
}
void loop() // run over and over again
{
// Basic colors:
color(255, 0, 0); // turn the RGB LED
red
delay(1000); // delay for 1 second
color(0,255, 0); // turn the RGB LED
green
delay(1000); // delay for 1 second
color(0, 0, 255); // turn the RGB LED
blue
delay(1000); // delay for 1 second
// Example blended colors:
color(255,255,0); // turn the RGB LED
yellow
delay(1000); // delay for 1 second
color(255,255,255); // turn the RGB
LED white
delay(1000); // delay for 1 second
color(128,0,255); // turn the RGB LED
purple
delay(1000); // delay for 1 second
color(0,0,0); // turn the RGB LED off
delay(1000); // delay for 1 second
}
void color (unsigned
char red, unsigned char green, unsigned char blue) // the color generating function
{
analogWrite(redPin, 255-red);
analogWrite(bluePin, 255-blue);
analogWrite(greenPin, 255-green);
}
訂閱:
文章 (Atom)


