Presentation is loading. Please wait.

Presentation is loading. Please wait.

講師:莊峻熙. #include Servo myservo; int motor = 10 ; int light = A0 ; int Lpin[] = {8,9,4,3,2,7,6,5}; void setup(){ int i; for(i=0;i<=7;i++){ pinMode(Lpin[i],OUTPUT);

Similar presentations


Presentation on theme: "講師:莊峻熙. #include Servo myservo; int motor = 10 ; int light = A0 ; int Lpin[] = {8,9,4,3,2,7,6,5}; void setup(){ int i; for(i=0;i<=7;i++){ pinMode(Lpin[i],OUTPUT);"— Presentation transcript:

1 講師:莊峻熙

2

3 #include Servo myservo; int motor = 10 ; int light = A0 ; int Lpin[] = {8,9,4,3,2,7,6,5}; void setup(){ int i; for(i=0;i<=7;i++){ pinMode(Lpin[i],OUTPUT); } pinMode(motor,OUTPUT); pinMode(light,INPUT); myservo.attach(motor); } void loop(){ int a = analogRead(light); a = a * 180 / 1024 ; myservo.write(a); a = a /20 +1 ; Led(a); } void Led(int a){ int L1[]={0,1,1,0,0,0,0,0}; int L2[]={1,1,0,1,1,0,1,0}; int L3[]={1,1,1,1,0,0,1,0}; int L4[]={0,1,1,0,0,1,1,0}; int L5[]={1,0,1,1,0,1,1,0}; int L6[]={1,0,1,1,1,1,1,0}; int L7[]={1,1,1,0,0,1,0,0}; int L8[]={1,1,1,1,1,1,1,0}; int L9[]={1,1,1,1,0,1,1,0}; int LN[]={0,0,0,0,0,0,0,0}; switch(a){ int i; case 1: for(i=0;i<=7;i++){ digitalWrite(Lpin[i],L1[i]); }

4 case 3: for(i=0;i<=7;i++){ digitalWrite(Lpin[i],L3[i]); } case 4: for(i=0;i<=7;i++){ digitalWrite(Lpin[i],L1[i]); } case 5: for(i=0;i<=7;i++){ digitalWrite(Lpin[i],L1[i]); } case 6: for(i=0;i<=7;i++){ digitalWrite(Lpin[i],L1[i]); } case 7: for(i=0;i<=7;i++){ digitalWrite(Lpin[i],L1[i]); } case 8: for(i=0;i<=7;i++){ digitalWrite(Lpin[i],L1[i]); } case 9: for(i=0;i<=7;i++){ digitalWrite(Lpin[i],L1[i]); } default : for(i=0;i<=7;i++){ digitalWrite(Lpin[i],LN[i]); }

5 #include Servo myservo; int val; void setup() { myservo.attach(12); } void loop() { val = analogRead(0); val = map(val, 0, 1023, 0, 179); myservo.write(val); delay(15); }

6 #include Servo myservo; int sensorLeft = 0; int sensorRight = 1; void setup() { Serial.begin(9600); myservo.attach(9); // Servo 接在 pin 9 } void loop() { int readingLeft, readingRight, difference; readingLeft = analogRead(sensorLeft); readingRight = analogRead(sensorRight); difference = abs(readingLeft - readingRight); if (difference <= 100) { myservo.write(90); delay(15); } else if (readingLeft > readingRight) { myservo.write(0); // 設定 Servo 旋轉角度 delay(15); // 等 Servo 旋轉 } else {myservo.write(180); // 設定 Servo 旋 轉角度 delay(15); // 等待 Servo 旋轉 } Serial.print("left: "); Serial.print(readingLeft); Serial.print(" right: "); Serial.println(readingRight); }

7 實際範例介紹 1. 綠能追日平台 https://www.youtube.com/watch?v=j0WWhd2rtxc 2. 光控手控自動窗簾 https://www.youtube.com/watch?v=SJaJsMXJgZk

8 Arduino 是如何打開想像力的 https://www.youtube.com/watch?v=jVUWT3tNT5o


Download ppt "講師:莊峻熙. #include Servo myservo; int motor = 10 ; int light = A0 ; int Lpin[] = {8,9,4,3,2,7,6,5}; void setup(){ int i; for(i=0;i<=7;i++){ pinMode(Lpin[i],OUTPUT);"

Similar presentations


Ads by Google