לימוד ארדואינו : שיעור 18 – פונקציות- קורס C506
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 |
int add(int a , int b ) { int c=0; c=a+b; return(c); } int sub(int a , int b ) { int c=0; c=a-b; return(c); } void setup() { // put your setup code here, to run once: int x; x=add(10,10); Serial.begin(9600); Serial.println("1 add :"); Serial.println(x); Serial.println("2 add :"); Serial.println(add(10,10)); Serial.println("3 sub :"); Serial.println(sub(10,10)); Serial.println("4 sub :"); Serial.println(sub(add(10,10),20)); Serial.println("3 sub :"); Serial.println(5*add(10,10)); } void loop() { // put your main code here, to run repeatedly: } |
חזרה על שילוב אלקטרוניקה
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 |
{ "version": 1, "author": "Arvind Patil", "editor": "wokwi", "parts": [ { "type": "wokwi-arduino-uno", "id": "uno", "top": 122.67, "left": -36.67, "attrs": {} }, { "type": "wokwi-buzzer", "id": "bz1", "top": -69.6, "left": 101, "attrs": { "volume": "0.1" } }, { "type": "wokwi-led", "id": "led1", "top": -9.81, "left": 281.17, "attrs": { "color": "green" } } ], "connections": [ [ "bz1:2", "uno:9", "red", [ "v89.07", "h-7.33" ] ], [ "bz1:1", "uno:GND.1", "black", [ "v75.73", "h-51.33" ] ], [ "led1:A", "uno:9", "red", [ "v84.4", "h168" ] ], [ "led1:C", "uno:GND.3", "black ", [ "v187.06", "h208" ] ] ] } |
קוד התוכנה
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 |
/* robotronix.co.il play tone with a loop */ const int speaker1 = 9; const int Led1 = 9; void setup() { pinMode(speaker1, OUTPUT); for(int i=0;i<5;i=i+1) { tone(speaker1, 1200); // Send 277KHz sound signal, which is a G tone delay(300); tone(speaker1, 1400); // Send 277KHz sound signal, which is a G tone delay(300); noTone(speaker1); // Stop sound delay(200); } } void loop() { } |