Task 1: Sensor Controlled Ellipse
I used a potentiometer to control the horizontal movement of an ellipse in p5.js. Additionally, I displayed text showing the connection status and the current position of the ellipse in (x, y) format.
My Sketch (with the P5js Code) can be found here:
My Arduino Code is here:
// Pin for reading analog values from sensor int Pin=A0; void setup() { Serial.begin(9600); } void loop() { //Reading values from sensor int sensor = analogRead(Pin); delay(5); //Writting the sensor value through serial Serial.println(sensor); }
Task 2: LED Brightness control from P5
I created a simple custom interface with On and Off Button to turn on the LED. While the LED is On there is a slider that can be adjusted to increase or decrease the brightness of the LED.
My Sketch (with the P5js Code) can be found here:
My Arduino Code is here:
// Setting Global Variables const int ledPin = 9; int brightness = 0; void setup() { pinMode(ledPin, OUTPUT); // Start serial communication Serial.begin(9600); } void loop() { // Check if data is available to read if (Serial.available()) { // Read Data as Integer int value = Serial.parseInt(); // Clear the serial data Serial.flush(); if (value > 0) { brightness = value; Serial.println(brightness); // Analog write the brightness analogWrite(ledPin, brightness); } }else { analogWrite(ledPin, 0); } }
Task 3: Bouncing Ball and Winds
In this activity, I started with the given sketch. I added LED lighting that activates whenever the balls touch the ground. The LEDs are controlled digitally by the balls as they make contact with the ground. Additionally, I included two potentiometers that act as wind controls for the ball’s horizontal movement. When the right wind is stronger than the left, the balls move toward the right, and vice versa. I also added an arrow to indicate the direction of the wind.
My Schematics can be seen here:
Here is the Video Demonstration:
My Sketch (with the P5js Code) can be found here:
My Arduino Code is here:
// Setting Global Variables const int ledPin1 = 9; const int ledPin2 = 6; int WindLeftPin=A0; int WindRightPin=A1; int brightness = 0; void setup() { pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); // Start serial communication Serial.begin(9600); } void loop() {if (Serial.available()) { int WindLeft = analogRead(WindLeftPin); int WindRight = analogRead(WindRightPin); Serial.print(WindLeft); Serial.print(","); Serial.print(WindRight); Serial.println(); int value = Serial.parseInt(); if (value == 0) { digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); } else if (value == 1) { digitalWrite(ledPin1, HIGH); digitalWrite(ledPin2, HIGH); } } }