top of page

Electroncis - 

אדרואינו - קוד בשפת C++ נורות מהבהבות.png

const int RED_PIN = 4;

const int YELLOW_PIN = 3;

const int GREEN_PIN = 2;

const int pot_pin = A0;

int pot_val;

 

void setup() {

  // put your setup code here, to run once:

Serial.begin(9600);

pinMode(RED_PIN, OUTPUT);

pinMode(YELLOW_PIN, OUTPUT);

pinMode(GREEN_PIN, OUTPUT);

}

 

void loop() {

  // put your main code here, to run repeatedly:

pot_val = analogRead(pot_pin);

Serial.println(pot_val);

if(pot_val <= 341){

  digitalWrite(RED_PIN, HIGH);

  digitalWrite(YELLOW_PIN, LOW);

  digitalWrite(GREEN_PIN, LOW);

}

else if(pot_val <= 682){

    digitalWrite(RED_PIN, LOW);

  digitalWrite(YELLOW_PIN, HIGH);

  digitalWrite(GREEN_PIN, LOW);

}

else{

  digitalWrite(RED_PIN, LOW);

  digitalWrite(YELLOW_PIN, LOW);

  digitalWrite(GREEN_PIN, HIGH);

  }

  delay(500);

}

const int RED_LED_PIN = 3;    // לד אדום מחובר לפין 3

const int POT_VAL = A0;         // פוטנציומטר מחובר לאנאלוג 0

int  HOW_MANY_TIMES;        // כמה פעמים ? מספר שלם

int LED_BRIGHTNESS;             //  בהירות לד. מספר שלם

int POT_READ;                         // קורא פוטנציומטר. מספר שלם 

 

void setup() {

  // put your setup code here, to run once:

pinMode(RED_LED_PIN, OUTPUT);            // מצב פין-פין לד אדום, פלט

Serial.begin(9600);                                        // רענן 9600 פעמים בדקה

}

 

void loop() {

  // put your main code here, to run repeatedly:

Serial.println("how many hivhuvim?");                 // הקלד שורה ועבור שורה - כמה הבהובים? 

 

while(Serial.available() == 0){                             // המתן לפקודה כלשהי

}

 

HOW_MANY_TIMES = Serial.parseInt();            // קרא את כמה פעמים להבהב

 

for(int i=1; i<= HOW_MANY_TIMES; i++){             // תריץ את מספר הבהובים הנדרש

 

POT_READ = analogRead(POT_VAL);                                      // קריאת הפוטנציומטר שווה לערך המתקבל באנאלוג

LED_BRIGHTNESS = map(POT_READ, 0, 1023, 0, 255);        //  מיפוי הערכים מפוטנציומטר ללד

 

analogWrite(RED_LED_PIN, LED_BRIGHTNESS);                 // האר את הלד לפי ערכי הפוטנציומטר

delay(300);                                                                               // המתן 300 מילי שניות

analogWrite(RED_LED_PIN, 0);                                               // כבה את הלד

delay(300);                                                                                // המתן 300 מילי שניות

 

}

 

}

#include <Servo.h>;                           // תכיר את הגדרות המנוע (אחת הספריות)

 

Servo myservo;                                   \\ 


 

const int FLAME_SENSOR = A0;                 \\  מספר שלם סנסור אש מגיע מA0

int val;                                                             \\ חכה לערך כלשהו

void setup() {

  // put your setup code here, to run once:

pinMode(FLAME_SENSOR, INPUT);                        \\ פין של סנסור אש הוא קלט 

Serial.begin(9600);                                                    \\ 

myservo.attach(3);                                                     \\ פין של המנוע הוא 3

}

void loop() {

  // put your main code here, to run repeatedly:

val =  analogRead(FLAME_SENSOR);                            \\ תקרא את הערך המגיע מהסנסור

Serial.println(val);                                                               \\ תדפיס את הערך בבקשה

if(val < 1010){                                                                       \\ אם הערך נמוך מ1010 אז 

 myservo.write(45);                                                               \\ תסובב מנוע ב45 מעלות

 delay(1000);                                                                            \\ חכה שנייה 

}

}

סופי.jpg
bottom of page