4134| 0
|
[项目] 用RGB灯条来显示植物是否缺水 |
刚从DFRobot这里拿到了RGB灯条,满喜欢的,本来就想做一个植物饥渴表示器的,这个RGB灯条刚好符合我意。 针脚其实一目了然 RGB用一个灯表现多钟颜色。而且无缝过度颜色 连线方式如上图,但实际我用了一个比较器,接线方式如下图。而主控用的是Arduino mini [mw_shl_code=applescript,true]//---------Created by gada888----------- const int analogInPin = A0; int sensorValue = 0; int red = 9; int green = 10; int blue = 11; //-----------SETUP PART---------- void setup() { Serial.begin(9600); pinMode(red, OUTPUT); pinMode(green, OUTPUT); pinMode(blue, OUTPUT); } //-----------LOOPING PART------------ void loop() { // Reading sensor value sensorValue = analogRead(analogInPin); Serial.println(sensorValue); //judgement of conditions if(sensorValue <=300){ //-----mapping value---------- map(sensorValue, 0, 300, 0, 255); digitalWrite(blue,HIGH); digitalWrite(green,HIGH); digitalWrite(red,LOW); } if(sensorValue >300){ map(sensorValue, 300, 600, 0, 255); digitalWrite(blue,HIGH); digitalWrite(green,LOW); digitalWrite(red,HIGH); } if(sensorValue >=600){ map(sensorValue, 600, 700, 0, 255); digitalWrite(blue,LOW); digitalWrite(green,HIGH); digitalWrite(red,HIGH); } }[/mw_shl_code] |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed