לימוד ארדואינו : תרגול 6 , קורס C506 הרצאה 7
פתור את התרגילים הבאים :
שאלה 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/* Global variable definition */ int A = 5 ; int B = 9 ; Void setup () { } Void loop () { /* check the boolean condition */ if (A > B) /* if condition is true then execute the following statement*/ {A++;} /* check the boolean condition */ If ( ( A < B ) && ( B != 0 )) /* if condition is true then execute the following statement*/ { A += B; B--; } } |
שאלה 2 – חשב כאשר
2.1 inputPin =1
2.2 וכאשר inputPin=0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
int ledPin = 13; // The pin the LED is connected to int inputPin = 2; // The input pin (for a push button) int inputStatus = 0; // Variable for reading the pin status // Executes once when the arduino power button is pressed on void setup() { pinMode(ledPin, OUTPUT); // Declare the LED as an output pinMode(inputPin, INPUT); // Declare pushbutton as input } // This method repeats forever // This method makes a led light when button is pushed void loop() { // Reads incomming input value from our inputPin inputStatus = digitalRead(inputPin); // Check if the input is HIGH (pushbutton released) if (inputStatus == HIGH) { digitalWrite(ledPin, LOW); // Turn the LED off } else { digitalWrite(ledPin, HIGH); // Turn the LED on } } |
שאלה 3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include <stdio.h> int main () { /* local variable definition */ int a = 100; /* check the boolean condition */ if( a < 20 ) { /* if condition is true then print the following */ printf("a is less than 20\n" ); } else { /* if condition is false then print the following */ printf("a is not less than 20\n" ); } printf("value of a is : %d\n", a); return 0; } |
שאלה 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 |
#include <stdio.h> int main () { /* local variable definition */ int a = 100; /* check the boolean condition */ if( a == 10 ) { /* if condition is true then print the following */ printf("Value of a is 10\n" ); } else if( a == 20 ) { /* if else if condition is true */ printf("Value of a is 20\n" ); } else if( a == 30 ) { /* if else if condition is true */ printf("Value of a is 30\n" ); } else { /* if none of the conditions is true */ printf("None of the values is matching\n" ); } printf("Exact value of a is: %d\n", a ); return 0; } |
שאלה 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
const int ledPin = 13; // The pin the LED is connected to const int ldrPin = A0; // The pin the LDR sensor is connected to int ldrStatus = 0; // Variable for reading the pin status // Executes once when the arduino power button is pressed on void setup() { pinMode(ledPin, OUTPUT); // Declare the LED as an output pinMode(ldrPin, INPUT); // Declare LDR Sensor as an input } // This method repeats forever void loop() { // Read incomming data from LRD sensor pin ldrStatus = analogRead(ldrPin); if (ldrStatus <= 400) { digitalWrite(ledPin, HIGH); //It's dark, Turn on LED } else { digitalWrite(ledPin, LOW); // It's bright, Turn off LED } } |