以下為電子實習的exam
需要材料:
Wire: n個
Button: 一個
330Ω Resistor: 五個
1kΩ Resistor: 一個
10kΩ Resistor: 一個
Potentiometer: 一個(不限電駔大小)
NPN 9013: 一個
Arduino Uno: 一個
LED: 五個
Breadboard: 一個
DC Motor: 一個
電路圖(Circuit diagram)
程式碼(Code)
int potenPin = A0; // 可變電阻 int buttonPin = 2; // 按鈕 int ledPins [] {3, 4, 5, 6, 7}; // led燈 int motorPin = 9; // 馬達 // 六段變速 100/300/500/700/900/1000 void setup() { Serial.begin(9600); pinMode(potenPin, INPUT); pinMode(buttonPin, INPUT); for(int L = 0; L < 5; L++) { pinMode(ledPins[L], OUTPUT); } pinMode(motorPin, OUTPUT); } void loop() { int motorValue = analogRead(potenPin); Serial.println(motorValue); int bStop = digitalRead(buttonPin); Serial.println(bStop); if (bStop == LOW) { if (motorValue < 100) { analogWrite(motorPin, 0); for (int L = 0; L < 5; L++) { digitalWrite(ledPins[L], LOW); } } else if (motorValue < 300) { analogWrite(motorPin, 300); for (int L = 0; L < 1; L++) { digitalWrite(ledPins[L], HIGH); } for (int L = 1; L < 5; L++) { digitalWrite(ledPins[L], LOW); } } else if (motorValue < 500) { analogWrite(motorPin, 500); for (int L = 0; L < 2; L++) { digitalWrite(ledPins[L], HIGH); } for (int L = 2; L < 5; L++) { digitalWrite(ledPins[L], LOW); } } else if (motorValue < 700) { analogWrite(motorPin, 700); for (int L = 0; L < 3; L++) { digitalWrite(ledPins[L], HIGH); } for (int L = 3; L < 5; L++) { digitalWrite(ledPins[L], LOW); } } else if (motorValue < 900) { analogWrite(motorPin, 900); for (int L = 0; L < 4; L++) { digitalWrite(ledPins[L], HIGH); } for (int L = 4; L < 5; L++) { digitalWrite(ledPins[L], LOW); } } else if (900 < motorValue) { analogWrite(motorPin, 1000); for (int L = 0; L < 5; L++) { digitalWrite(ledPins[L], HIGH); } } } else if (bStop == HIGH) { for(int s = 0; s < 5; s++) { digitalWrite(ledPins[s],LOW); } digitalWrite(motorPin,LOW); delay(100); } }
影片(Video)
small exam from 40423222 on Vimeo.
參考網站:
levelMotor:
https://40423222.github.io/2017springcd_hw/blog/Arduino-threeLevel_Motor.html
參考對象:
https://40423222.github.io/2017springcd_hw/blog/
參考對象: