Arduino !!
Firstly, we were challenged. Challenged to do what you may ask? Well we were challenged to do 4 tasks, in which they took all of our brain power and sucked our brain juices dry!! Im kidding, these challenged we farely manageable except for the DC motor one (ive yet to complete it my brain circuits are fried!! HAHAHAH get it? circuits? Arduino?? Okay enough joking lets get into the electrifying part of the challenge.
For the first challenge, we had to interface a potentiometer analog input.
In case the code seems blurry or small, I will input the codes after the scenario.
int sensorVal = 0;
void setup()
{
pinMode(A0, INPUT);
pinMode(13, OUTPUT);
}
void loop()
{
sensorVal = analogRead(A0);
digitalWrite(13, HIGH);
delay(sensorVal); // Wait for 1000 * sensorVal millisecond(s)
digitalWrite(13, LOW);
delay(sensorVal); // Wait for 1000 * sensorVal millisecond(s)
}
The signal monitor read O, so yeah... I did not take a screenshot of that
int led = 7;
int ldr = A0;
void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(ldr, INPUT);
}
void loop() {
int ldrValue = analogRead(ldr);
Serial.println(ldrValue);
if (ldrValue <=5) {
digitalWrite(led, HIGH);
}
else {
digitalWrite(led, LOW);
}
}
For the third challenge, we had to create a flash/fade using the LEDs in a red yellow green sequence
I picked flash, hence why the low values do not have delay !!
int red = 9;
int yellow = 8;
int green = 7;
void setup() {
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
}
void loop() {
digitalWrite(red, HIGH);
delay(1000);
digitalWrite(red, LOW);
digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);
digitalWrite(green, HIGH);
delay(1000);
digitalWrite(green, LOW);
}
No comments:
Post a Comment