לימוד ארדואינו : שיעור 5 כניסה אנלוגית , וקריאת מתח – קורס C506
בשיעור זה נוסיף עוד שלב על משפט תנאי IF וזה החלק הנוסף ELSE , בנוסף נילמד על כניסה אנלודית וקריאה של ערך אנלוגי מבקר ארדואינו
נשתמש בסכמה הבאה לבניית מעגל עם מיקרובקר ארדואינו – עבור פיתוח אמבדד
שלב ראשון ניפתח את האתר https://wokwi.com/
לימוד אמבדד , לימוד ארדואינותרגיל 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
// www.robotronix.co.il // ----------------------------------------------------- // 0V , analogRead(A1); --> 0 // 2.5V , analogRead(A1); --> 512 // 5V , analogRead(A1); --> 1023 // ----------------------------------------------------- void setup() { Serial.begin(115200); pinMode(A1, INPUT); // set pin as input } void loop() { int SpeedControl = analogRead(A1); //Serial.println(value); Serial.print("Motor speed control : "); Serial.println(SpeedControl); if(SpeedControl==0) { Serial.println("Motor stop"); } if(SpeedControl>0) { Serial.println("Motor run "); } delay(1000); } |
תרגיל 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
// www.robotronix.co.il // ----------------------------------------------------- // 0V , analogRead(A1); --> 0 // 2.5V , analogRead(A1); --> 512 // 5V , analogRead(A1); --> 1023 // ----------------------------------------------------- void setup() { Serial.begin(115200); pinMode(A1, INPUT); // set pin as input } void loop() { int SpeedControl = analogRead(A1); //Serial.println(value); Serial.print("Motor speed control : "); Serial.println(SpeedControl); if(SpeedControl==0) { Serial.println("Motor stop"); } if(SpeedControl>0) { if(SpeedControl<200) { Serial.println("Motor run Low Speed"); } else { Serial.println("Motor run Low Speed"); } } delay(1000); } |
תרגיל 3 : נשתמש ב ב AND לוגי
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
// www.robotronix.co.il // ----------------------------------------------------- // 0V , analogRead(A1); --> 0 // 2.5V , analogRead(A1); --> 512 // 5V , analogRead(A1); --> 1023 // ----------------------------------------------------- void setup() { Serial.begin(115200); pinMode(A1, INPUT); // set pin as input } void loop() { int SpeedControl = analogRead(A1); //Serial.println(value); Serial.print("Motor speed control : "); Serial.println(SpeedControl); if(SpeedControl==0) { Serial.println("Motor stop"); } if(SpeedControl>0) { if ( (SpeedControl<=200) ) { Serial.println("Motor run Low Speed"); } if ( (SpeedControl >200) && (SpeedControl<=500) ) { Serial.println("Motor run Mediun Speed"); } if ( (SpeedControl >500 ) { Serial.println("Motor run High Speed"); } } delay(1000); } |