top of page

Electronics - 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);


}

Electronics - Exercise 2

// the lrds are connected to pins 3,4,5: 

 const int Red_led=3; 

 const int Yellow_led=5; 

const int Green_led=4; 

// the potentiometer is connectedd to pin A0 

const int Poten pin=A0; 

//define variables 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, 180,660,50, 1000); 

//turn on Red 

 digitalWrite(Red_led, HIGH); 

digitalWrite(Yellow_led, LOW); 

digitalWrite(Green_led, LOW); 

delay(rhythm);

//turn on Yellow digitalWrite(Red_led, LOW); 

digitalWrite(Yellow_led, HIGH); 

digitalWrite(Green_led, LOW); 

delay(rhythm);

//turn on Green 

digitalWrite(Red_led, LOW); 

digitalWrite(Yellow_led, LOW); 

digitalWrite(Green_led, HIGH); 

delay(rhythm); 4

Electronics - Exercise 3

#include <Servo.h>

Servo SarinStepper;

 

void setup() {

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

SarinStepper.attach(9);

}

 

void loop() {

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

SarinStepper.write(0);

delay(100);

SarinStepper.write(180);

delay(100);

}

const int buzz_pin=3;

const int dtimeL=1000;

const int dtimeS=dtimeL/2;

 

const int G=392;

const int F=349;

const int E=329;

const int D=293;

const int C=261;

const int B=246;

const int A=220;

 

void setup() {

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

 

}

 

void loop() {

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

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);

}

Electronics - Exercise 4

const int SW_pin = 2; // החיבור ליציאת סוויצ

const int X_pin = 0; // החיבור לציר X

const int Y_pin = 1; // החיבור לציר Y

 

 

#define UP_LED 8

#define RIGHT_LED 9 

#define LEFT_LED 10

#define DOWN_LED 11

 

 

 

 

//הגדרת אינפוט ואאוטפוט לכל המעגל

 

void setup() {

  pinMode(SW_pin, INPUT);

  digitalWrite(SW_pin, HIGH);

  Serial.begin(115200);

 

 

  pinMode(UP_LED , OUTPUT);

  pinMode(RIGHT_LED , OUTPUT);

  pinMode(LEFT_LED , OUTPUT);

  pinMode(DOWN_LED , OUTPUT);

 

}

//הגדרת פעולות עם תזוזת הג'וייסטיק

void loop() {

  Serial.print("Switch:  ");

  Serial.print(digitalRead(SW_pin));

  Serial.print("\n");

  Serial.print("X-axis: ");

  Serial.print(analogRead(X_pin));

  Serial.print("\n");

  Serial.print("Y-axis: ");

  Serial.println(analogRead(Y_pin));

  Serial.print("\n\n");

  

  delay(500);

 

//הגדרת הדלקת נורה לפי התזוזה המתאימה לה

  if(analogRead(X_pin) == 1023){

    digitalWrite(UP_LED , HIGH);

 

 } else if(analogRead(X_pin) == 0){

    digitalWrite(DOWN_LED , HIGH);

}

 

else if(analogRead(Y_pin) == 1023){

    digitalWrite(RIGHT_LED , HIGH);

}

 

else if(analogRead(Y_pin) == 0){

    digitalWrite(LEFT_LED , HIGH);

 

}

 

else if(digitalRead(SW_pin) == 0){

digitalWrite(UP_LED , HIGH);

digitalWrite(LEFT_LED , HIGH);

digitalWrite(RIGHT_LED , HIGH);

digitalWrite(DOWN_LED , HIGH);

 

 

}

 

 

//ללא קבלת קלט מהג'וייסטיק להשאיר הכל כבוי

 

else{

digitalWrite(UP_LED , LOW);

digitalWrite(LEFT_LED , LOW);

digitalWrite(RIGHT_LED , LOW);

digitalWrite(DOWN_LED , LOW);

 

  

  

}

  }

DIGITAL MATERIAL CULTURE - Sarin Malk

©2022 by DIGITAL MATERIAL CULTURE - Sarin Malk. Proudly created with Wix.com

bottom of page