רובוטיקס בלוקס – קורס RB10 – שיעור 2
מטרת השיעור : להכיר את המיקרו בקר , כתיבת קוד תוכנה ראשוני , בניית לד מהבהב , בניית לדים משטרה , טיפול בשגיעות קומפילציה
דוגמא 1 : כתיבה על המסך
- מבנה כללי של משפט בשפת C , מסתיים עם נקודה פסיק
- חלק של SETUP חלק של LOOP
- הבדלים בין אותיות קטנות לגדולות
- קישור – לתוכנה קיימת : https://wokwi.com/projects/342677594629472850
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// רובוטיקס בלוקס - קורס RB10 - שיעור 2 // void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println("start"); } void loop() { // put your main code here, to run repeatedly: } |
תרגיל : שנה את ההודעה לשמך הפרוטי באנגלית והרץ את התוכנית
דוגמא 2 הוספת לד
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
// רובוטיקס בלוקס - קורס RB10 - שיעור 2 // void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println("start"); pinMode(7, OUTPUT); // pin set up as output digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level) delay(500); // wait for a second ( 1000= 1 sec ) digitalWrite(7, LOW); // turn the LED off by making the voltage LOW delay(500); // wait for a second ( 1000= 1 sec ) } void loop() { // put your main code here, to run repeatedly: } |
להסביר :
- מה זה קומפיילר , קוד מכונה , קוד אדם
- מה זה צורב programmer
דוגמא 3 – שימוש בלולאה
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println("start"); } void loop() { // put your main code here, to run repeatedly: pinMode(7, OUTPUT); // pin set up as output digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second ( 1000= 1 sec ) digitalWrite(7, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second ( 1000= 1 sec ) } |
דוגמא 4
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 |
// רובוטיקס בלוקס - קורס RB10 - שיעור 2 // void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println("start"); pinMode(7, OUTPUT); // pin set up as output pinMode(4, OUTPUT); // pin set up as output } void loop() { // put your main code here, to run repeatedly: digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level) delay(500); // wait for a second ( 1000= 1 sec ) digitalWrite(7, LOW); // turn the LED off by making the voltage LOW delay(500); // wait for a second ( 1000= 1 sec ) digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level) delay(500); // wait for a second ( 1000= 1 sec ) digitalWrite(4, LOW); // turn the LED off by making the voltage LOW delay(500); // wait for a second ( 1000= 1 sec ) } |
דוגמא 5: הבהוב מהיר
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 |
// רובוטיקס בלוקס - קורס RB10 - שיעור 2 // void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println("start"); pinMode(7, OUTPUT); // pin set up as output pinMode(7, OUTPUT); // pin set up as output } void loop() { // put your main code here, to run repeatedly: digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second ( 1000= 1 sec ) digitalWrite(7, LOW); // turn the LED off by making the voltage LOW delay(100); // wait for a second ( 1000= 1 sec ) digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second ( 1000= 1 sec ) digitalWrite(4, LOW); // turn the LED off by making the voltage LOW delay(100); // wait for a second ( 1000= 1 sec ) } |
דוגמא 6 : תרגול תקלות כתיב בתוכנה – הורדת נקודה פסיק בשורה 7
י
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// רובוטיקס בלוקס - קורס RB10 - שיעור 2 // void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println("start") } void loop() { // put your main code here, to run repeatedly: } |
דוגמא 7 : תרגול תקלות כתיב בתוכנה – כתיבת באות קטנה את המילה serial
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// רובוטיקס בלוקס - קורס RB10 - שיעור 2 // void setup() { // put your setup code here, to run once: serial.begin(9600); ;Serial.println("start") } void loop() { // put your main code here, to run repeatedly: } |
תרגיל המשך למי סיים
- הוספת לד בצבע ירוק והוספה להבהוב
- כתיבה למסך בכל פעם שלד אדום דלוק ON ובכל פעם שהוא כבוי OFF