LILIAN KHOURY
DIGITAL MATERIAL CULTURE
2022-2023
Exercise 1
const int red_led_pin=3;
const int yellow_led_pin=4;
const int green_led_pin=5;
void setup() {
// put your setup code here, to run once:
pinMode(red_led_pin,OUTPUT);
pinMode(yellow_led_pin,OUTPUT);
pinMode(green_led_pin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(red_led_pin,HIGH);
delay(100);
digitalWrite(red_led_pin,LOW);
delay(100);
digitalWrite(red_led_pin,HIGH);
delay(100);
digitalWrite(red_led_pin,LOW);
delay(70);
digitalWrite(yellow_led_pin,HIGH);
delay(100);
digitalWrite(yellow_led_pin,LOW);
delay(100);
digitalWrite(yellow_led_pin,HIGH);
delay(100);
digitalWrite(yellow_led_pin,LOW);
delay(70);
digitalWrite(green_led_pin,HIGH);
delay(100);
digitalWrite(green_led_pin,LOW);
delay(100);
digitalWrite(green_led_pin,HIGH);
delay(100);
digitalWrite(green_led_pin,LOW);
delay(70);
}

Exercise 2
// the leds are coonected to pins 3,4,5:
const int Red_led = 3;
const int Yellow_led = 4;
const int Green_led = 5;
// the poteniometer is coonectedto pin A0:
const int Poten_pin = A0;
// defin varibles to contain data:
int poten_val;
int rhythm;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(Red_led, OUTPUT);
pinMode(Yellow_led, OUTPUT);
pinMode(Green_led, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
poten_val = analogRead(Poten_pin);
Serial.println(poten_val);
rhythm = map(poten_val , 0 , 1023 , 50 , 1000);
// tern on RED
digitalWrite(Red_led, HIGH);
digitalWrite(Yellow_led, LOW);
digitalWrite(Green_led, LOW);
delay(rhythm);
// tern on YELLOW
digitalWrite(Red_led, LOW);
digitalWrite(Yellow_led, HIGH );
digitalWrite(Green_led, LOW);
delay(rhythm);
// tern on GREEN
digitalWrite(Red_led, LOW);
digitalWrite(Yellow_led, LOW);
digitalWrite(Green_led, HIGH);
delay(rhythm);
}

Exercise 3
#include <LCD_I2C.h>
LCD_I2C lcd(0x27, 16,2);
const int H20_sensor = A0;
int H20_level;
void setup() {
// put your setup code here, to run once:
lcd.begin();
lcd.backlight();
}
void loop() {
// put your main code here, to run repeatedly:
lcd.setCursor(0, 0);
lcd.print("THIS IS A");
lcd.setCursor(4, 1);
lcd.print("WATER SENSOR");
delay(1000);
lcd.clear();
H20_level = analogRead(H20_sensor);
lcd.setCursor(0, 0);
lcd.print("WATER LEVEL IS:");
lcd.setCursor(0, 1);
lcd.print(H20_level);
delay(1000);
lcd.clear();
}


Exercise 4
#include <LCD_I2C.h>
LCD_I2C lcd(0x27, 16,2);
//הגדרת כפתור למספר פין
const int button1 = 8;
const int button2 = 10;
const int dtimeL = 1000;
const int dtimeS = dtimeL/2;
// הגדרת רמקול למספר פין
const int buzz_pin = 2;
//הגדרת הרץ לכל תו
int G = 392;
int F = 349;
int E = 329;
int D = 293;
int C = 261;
int B = 246;
int A = 220;
void setup() {
// put your setup code here, to run once:
lcd.begin();
lcd.backlight();
Serial.begin(9600);
pinMode(button1,INPUT_PULLUP);
pinMode(button2,INPUT_PULLUP);
}
void loop() {
// הוראת טקסט
lcd.setCursor(0, 0);
lcd.print("CHOOSE ONE OF");
lcd.setCursor(0, 1);
lcd.print("THE TWO SONGS:");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SONG NUM 1:");
lcd.setCursor(0, 1);
lcd.print("YONATAN HAKATAN");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SONG NUM 2:");
lcd.setCursor(0, 1);
lcd.print("MATANOT KTANOT");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("WAITING FOR YOUR");
lcd.setCursor(0, 1);
lcd.print("CHOICE");
delay(3000);
lcd.clear();
// הוראת הפסקה עד ללחיצה על כפתור
while( digitalRead(button1) == 1 && digitalRead(button2) == 1 ){
}
// לחיצה על כפתור 1 תנגן שיר
if(digitalRead(button1) == 0){
tone(buzz_pin, G, 500);
delay(dtimeS);
tone(buzz_pin, E, 500);
delay(dtimeS);
tone(buzz_pin, E, 500);
delay(dtimeL);
tone(buzz_pin, F, 500);
delay(dtimeS);
tone(buzz_pin, D, 500);
delay(dtimeS);
tone(buzz_pin, D, 500);
delay(dtimeL);
tone(buzz_pin, C, 500);
delay(dtimeS);
tone(buzz_pin, D, 500);
delay(dtimeS);
tone(buzz_pin, E, 500);
delay(dtimeS);
tone(buzz_pin, F, 500);
delay(dtimeS);
tone(buzz_pin, G, 500);
delay(dtimeS);
tone(buzz_pin, G, 500);
delay(dtimeS);
tone(buzz_pin, G, 500);
delay(dtimeL);
noTone(buzz_pin);
}
if(digitalRead(button2) == 0){
tone(buzz_pin, G, 500);
delay(dtimeS);
tone(buzz_pin, G, 500);
delay(dtimeS);
tone(buzz_pin, B, 500);
delay(dtimeS);
tone(buzz_pin, D, 500);
delay(dtimeS);
tone(buzz_pin, D, 500);
delay(dtimeL);
tone(buzz_pin, B, 500);
delay(dtimeS);
tone(buzz_pin, A, 500);
delay(dtimeL);
tone(buzz_pin, A, 500);
delay(dtimeS);
tone(buzz_pin, B, 500);
delay(dtimeS);
tone(buzz_pin, C, 500);
delay(dtimeL);
tone(buzz_pin, D, 500);
delay(dtimeS);
tone(buzz_pin, C, 500);
delay(dtimeS);
tone(buzz_pin, B, 500);
delay(dtimeS);
tone(buzz_pin, G, 500);
delay(dtimeL);
noTone(buzz_pin);
}
}

