top of page

POTENTIOMETER CODE:

const int pin_red = 3; // הגדרת פין ללד //const ערך קבוע

const int pot_pin= A0; //הגדרת פטנציומטר ממקור אנלוגי מספר 0

int pot_val; //הגדרת משתנה

int howmanytimes ;

int ledbrightness;

 

void setup() {

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

pinMode(pin_red,OUTPUT);

Serial.begin(9600);//הגדרה ראשונית

 

}

 

void loop() {

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

 

Serial.println("?how many hivhivim?"); // שואל את המשתמש כמה הבהובים

 

while(Serial.available()==0){// האם יש מידע בתיבה

// כל עוד לא נכנס מידע התוכנה נעצרת

}


 

howmanytimes = Serial.parseInt();// קבלת הקלט


 

for (int i=howmanytimes ; i>=0 ;i--){


 

pot_val = analogRead(pot_pin); // הכנסת הערך המספרי של הפטוציומטר למשתנה

 

ledbrightness = map(pot_val,0,1023,0,255);//המרת המשתנה המתקבל לטווח הרצוי של המקבל map(טווח מקסימלי של מי שמקבל,טווח מינימלי,טווח מקסימלי,טווח מינימלי של מי שמקבל,ערך שאני רוצה למפות;

 

analogWrite( pin_red, ledbrightness);//הדלקת המנורה לפי משתנה אנלוגי (עוצמת הנורה משתנה)

 

delay (300);

analogWrite( pin_red, 0);//כיבוי

delay (300);

 

}

}

©2022 by My Site. Proudly created with Wix.com

bottom of page