掃描版本
int sensorPin = A0; // select the input pin for the potentiometerint ledPin = 4; // select the pin for the LEDint sensorValue = 0; // variable to store the value coming from the sensorint count = 0; float block; boolean ctl=true,dis=true; void setup() { while(++ledPin<=11) pinMode(ledPin, OUTPUT); Serial.begin(9600); } void loop() { ledPin = count%8+5; sensorValue = analogRead(sensorPin); Serial.print("Now blink : "); Serial.println(sensorValue); if(dis==true){ digitalWrite(ledPin, HIGH); delay(sensorValue); } else{ digitalWrite(ledPin,LOW); delay(sensorValue); } if(ctl==true){ if(dis==true) count++; else count--; } else{ if(dis==true) count--; else count++; } if(count%7==0) dis=!dis; if(dis==false&&count%7==0) ctl=!ctl; }
來回版本1
int sensorPin = A0; // select the input pin for the potentiometerint ledPin = 4; // select the pin for the LEDint sensorValue = 0; // variable to store the value coming from the sensorint count = 0; float block; boolean ctl=true,dis=true; void setup() { while(++ledPin<=11) pinMode(ledPin, OUTPUT); Serial.begin(9600); } void loop() { ledPin = count%8+5; sensorValue = analogRead(sensorPin); Serial.print("Now blink : "); Serial.println(sensorValue); if(dis==true){ digitalWrite(ledPin, HIGH); delay(sensorValue); } else{ digitalWrite(ledPin,LOW); delay(sensorValue); } if(ctl==true){ if(dis==true) count++; else count--; } else{ if(dis==true) count--; else count++; } if(count%7==0) dis=!dis; if(dis==false&&count%7==0) ctl=!ctl; }來回版本2
int sensorPin = A0; // select the input pin for the potentiometerint ledPin = 4; // select the pin for the LEDint sensorValue = 0; // variable to store the value coming from the sensorint count = 0; float block; boolean ctl=true; void setup() { while(++ledPin<=11) pinMode(ledPin, OUTPUT); Serial.begin(9600); } void loop() { ledPin = count%8+5; // read the value from the sensor: sensorValue = analogRead(sensorPin); // turn the ledPin on Serial.print("Now blink : "); Serial.println(sensorValue); if(ctl==false){ digitalWrite(ledPin, LOW); delay(sensorValue); } else{ digitalWrite(ledPin, HIGH); delay(sensorValue); } if(ctl==true) count++; else count--; if(count%7==0) ctl=!ctl; }控制版本
int sensorPin = A0; // select the input pin for the potentiometerint ledPin = 4; // select the pin for the LEDint sensorValue = 0; // variable to store the value coming from the sensorint count = 0; float block; boolean ctl=true; void setup() { while(++ledPin<=11) pinMode(ledPin, OUTPUT); ledPin=0; block = 1024/7.0; Serial.begin(9600); } void loop() { sensorValue = analogRead(sensorPin); count = sensorValue/block; for(int i=0;i<7;i++){ if(i==count) digitalWrite(i%7+5,HIGH); else digitalWrite(i%7+5, LOW); } Serial.print("Now blink : "); Serial.println(sensorValue); }
1.2 心得:
今天算是真正的花了時間去撰寫arduino的程式,使用起來的感覺,與一般程式不同。相較之下,今天的比較有樂趣,或許是因為成果不僅僅侷限在螢幕,而是能夠在實體上互動。這種感覺真的非常的有趣。
我想在下星期學習輸入方式之後,期末的作品能製作的專題,似乎又多了很多方向。我想期末的時候,作品會針對是要有足夠的互動性,要能展現搭配了Arduino的特色吧。
沒有留言:
張貼留言