Day 2:
[embedpress]https://docs.google.com/presentation/d/e/2PACX-1vTR2o42luN6ECQHrWZqFFO7_wfKbp-bjrfqcY-evcI-A8onp388S7jUPB0smwz-Hira98uywo4Fr5GE/pub?start=false&loop=false&delayms=60000[/embedpress]
Click on this link to view on your Browser:
https://docs.google.com/presentation/d/17AL_fu6FzBVkZ5ajBMr1QRTtgWIIMu7MZcmTqXQQJkQ/edit?usp=sharing
9 LED Pattern Code:
int t = 40; int rnd =5; int pat1t =75; void setup() { for(int i=3; i<=12; i++) pinMode(i,OUTPUT); } void loop(){ for(int i=0; i<=rnd; i++) { pat1();} for(int i=0; i<=rnd; i++){ pat2();} for(int i=0; i<=rnd; i++) { pat3();} for(int i=0; i<=rnd; i++) { pat4();} for(int i=0; i<=rnd; i++){ pat5();} for(int i=0; i<=rnd; i++) { pat6();} for(int i=0; i<=rnd; i++) { pat7();} for(int i=0; i<=rnd; i++) { pat8();} for(int i=0; i<=rnd; i++) { pat9();} } void pat1(){ for(int i=3; i<=12; i++) { digitalWrite(i,HIGH); delay(pat1t); digitalWrite(i,LOW); } for(int i=11; i>=4; i--) { digitalWrite(i,HIGH); delay(pat1t); digitalWrite(i,LOW); } } void pat2(){ for(int i=3; i<=12; i++) { digitalWrite(i,HIGH); digitalWrite(i-1,HIGH); digitalWrite(i+1,HIGH); delay(100); digitalWrite(i,LOW); digitalWrite(i-1,LOW); digitalWrite(i+1,LOW); } for(int i=11; i>=4; i--) { digitalWrite(i,HIGH); digitalWrite(i-1,HIGH); digitalWrite(i+1,HIGH); delay(100); digitalWrite(i,LOW); digitalWrite(i-1,LOW); digitalWrite(i+1,LOW); } } void pat3(){ for(int i=3; i<=12; i=i+2) { digitalWrite(i,HIGH); delay(100); digitalWrite(i,LOW); } for(int i=12; i>=3; i=i-2) { digitalWrite(i,HIGH); delay(100); digitalWrite(i,LOW); } } void pat4(){ for(int i=3; i<=12; i++) { digitalWrite(i,HIGH); delay(100); } for(int i=12; i>=2; i--) { digitalWrite(i,HIGH); delay(100); digitalWrite(i,LOW); } } void pat5(){ for(int i=3; i<=12; i++) { digitalWrite(i,HIGH); } delay(100); for(int i=3; i<=12; i++) { digitalWrite(i,LOW); } delay(100); } void pat6(){ for(int i=3; i<=8; i++) { digitalWrite(i,HIGH); } for(int i=8; i<=12; i++) { digitalWrite(i,LOW); } delay(200); for(int i=3; i<=8; i++) { digitalWrite(i,LOW); } for(int i=8; i<=12; i++) { digitalWrite(i,HIGH); } delay(200); } void pat7(){ for(int i=3; i<=12; i=i+2) { digitalWrite(i,HIGH); } for(int i=4; i<=12; i=i+2) { digitalWrite(i,LOW); } delay(200); for(int i=3; i<=12; i=i+2) { digitalWrite(i,LOW); } for(int i=4; i<=12; i=i+2) { digitalWrite(i,HIGH); } delay(200); } void pat8(){ digitalWrite(7,HIGH); digitalWrite(8,HIGH); delay(t); digitalWrite(7,LOW); digitalWrite(8,LOW); delay(t); digitalWrite(6,HIGH); digitalWrite(9,HIGH); delay(t); digitalWrite(6,LOW); digitalWrite(9,LOW); delay(t); digitalWrite(5,HIGH); digitalWrite(10,HIGH); delay(t); digitalWrite(5,LOW); digitalWrite(10,LOW); delay(t); digitalWrite(4,HIGH); digitalWrite(11,HIGH); delay(t); digitalWrite(4,LOW); digitalWrite(11,LOW); delay(t); digitalWrite(3,HIGH); digitalWrite(12,HIGH); delay(t); digitalWrite(3,LOW); digitalWrite(12,LOW); delay(t); digitalWrite(4,HIGH); digitalWrite(11,HIGH); delay(t); digitalWrite(4,LOW); digitalWrite(11,LOW); delay(t); digitalWrite(5,HIGH); digitalWrite(10,HIGH); delay(t); digitalWrite(5,LOW); digitalWrite(10,LOW); delay(t); digitalWrite(6,HIGH); digitalWrite(9,HIGH); delay(t); digitalWrite(6,LOW); digitalWrite(9,LOW); delay(t); } void pat9(){ for(int i=3; i<=12; i++) { digitalWrite(i,HIGH); } for(int i=3; i<=12; i++) { digitalWrite(i,LOW); delay(100); digitalWrite(i,HIGH); } for(int i=11; i>=4; i--) { digitalWrite(i,LOW); delay(100); digitalWrite(i,HIGH); } }
Ultrasonic Sensor Code:
// defines pins numbers
const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT);
// Sets the trigPin as an Output
pinMode(echoPin, INPUT);
// Sets the echoPin as an Input
Serial.begin(9600);
// Starts the serial communication
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print(“Distance: “);
Serial.println(distance);
}
LDR Code:
#define LDRpin A0 // pin where we connected the LDR and the resistor
int LDRValue = 0; // result of reading the analog pin
void setup() {
Serial.begin(9600); // sets serial port for communication
}
void loop() {
LDRValue = analogRead(LDRpin); // read the value from the LDR
Serial.println(LDRValue); // print the value to the serial port
delay(100); // wait a little
}