top of page

Ellectronics

שיעור 2

const int RED_LED_PIN = 4;

const int GREEN_LED_PIN = 8;

const int YELLOW_LED_PIN = 12;

const int poten_pin = A0;

int poten_value;

// הטווח של הווליום הוא בין 0 ל1023

const int button_pin = 13;

 

void setup() {

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

pinMode(RED_LED_PIN, OUTPUT);

pinMode(GREEN_LED_PIN, OUTPUT);

pinMode(YELLOW_LED_PIN, OUTPUT);

pinMode(button_pin, INPUT_PULLUP);

Serial.begin(9600); // מספר קבוע, מספר פעמים בשנייה שהמחשב והארדואינו מתקשרים ביניהם

}

 

void loop() {

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

while(digitalRead(button_pin)==1){

}

 

poten_value =analogRead(poten_pin);

Serial.println(poten_value);

 

if (poten_value<=341){

digitalWrite(RED_LED_PIN, HIGH);

digitalWrite(GREEN_LED_PIN, LOW);

digitalWrite(YELLOW_LED_PIN, LOW);

 

}

else if(poten_value<=682){

digitalWrite(RED_LED_PIN, LOW);

digitalWrite(GREEN_LED_PIN, HIGH);

digitalWrite(YELLOW_LED_PIN, LOW);

 

}

else{

digitalWrite(RED_LED_PIN, LOW);

digitalWrite(GREEN_LED_PIN, LOW);

digitalWrite(YELLOW_LED_PIN, HIGH);  

}


 

}

const int RED_LED_PIN = 4;

const int GREEN_LED_PIN = 8;

const int YELLOW_LED_PIN = 12;

const int poten_pin = A2;

int poten_value;

// הטווח של הווליום הוא בין 0 ל1023

const int button_pin = 13;

bool ani_madlika = false;

 

void setup() {

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

pinMode(RED_LED_PIN, OUTPUT);

pinMode(GREEN_LED_PIN, OUTPUT);

pinMode(YELLOW_LED_PIN, OUTPUT);

pinMode(button_pin, INPUT_PULLUP);

Serial.begin(9600); // מספר קבוע, מספר פעמים בשנייה שהמחשב והארדואינו מתקשרים ביניהם

}

 

void loop() {

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

if(digitalRead(button_pin)==0){

  ani_madlika = !ani_madlika;

}


 

poten_value =analogRead(poten_pin);

Serial.println(poten_value);

 

if(ani_madlika == true){


 

                      if (poten_value<=341){

                      digitalWrite(RED_LED_PIN, HIGH);

                      digitalWrite(GREEN_LED_PIN, LOW);

                      digitalWrite(YELLOW_LED_PIN, LOW);

 

                      }

                      else if(poten_value<=682){

                      digitalWrite(RED_LED_PIN, LOW);

                      digitalWrite(GREEN_LED_PIN, HIGH);

                      digitalWrite(YELLOW_LED_PIN, LOW);

 

                      }

                      else{

                      digitalWrite(RED_LED_PIN, LOW);

                      digitalWrite(GREEN_LED_PIN, LOW);

                      digitalWrite(YELLOW_LED_PIN, HIGH);  

                      }

 

                      }

 

else{

digitalWrite(RED_LED_PIN, LOW);

digitalWrite(GREEN_LED_PIN, LOW);

digitalWrite(YELLOW_LED_PIN, LOW);  

 

}

}

RGB Led pin

const int Rpin=9;

const int Gpin=10;

const int Bpin=11;


 

void setup() {

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

pinMode(Rpin, OUTPUT);

pinMode(Gpin, OUTPUT);

pinMode(Bpin, OUTPUT);

}

 

void loop() {

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

  for(int i =255; i<=255; i--){

analogWrite(Rpin, i);

analogWrite(Gpin, 0);

analogWrite(Bpin, 255-i);

delay(10);

  }


 

}

Final program- water sensor with Led

int value;

void setup() {

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

  pinMode(A0, INPUT);

  pinMode(13, OUTPUT);

  pinMode(12, OUTPUT);

  pinMode(11, OUTPUT);

 

}

 

void loop() {

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

  value = analogRead(A0) ;

  if(value <= 250)

  {

    digitalWrite(13, 1); // Green

    digitalWrite(12, 0); // Yellow

    digitalWrite(11, 0); // Red

  }

  else if(value <= 650)

  {

    digitalWrite(13, 0); // Green

    digitalWrite(12, 1); // Yellow

    digitalWrite(11, 0); // Red

  }

  else

  {

    digitalWrite(13, 0); // Green

    digitalWrite(12, 0); // Yellow

    digitalWrite(11, 1); // Red

  }

}

bottom of page