From 8670841eb01fb923287661b9750020861d33b569 Mon Sep 17 00:00:00 2001 From: ckd2-elford <cosmo2.elford@live.uwe.ac.uk> Date: Tue, 7 Nov 2023 19:15:06 +0000 Subject: [PATCH] Update file README.md --- README.md | 56 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 9283da2..eae0b3e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# DD Worksheet 1 +# Worksheet 1 By <b>Cosmo Elford</b> 201018021 # Task 1, 2 (Getting started) Getting the LED to turn on with a battery and 220 Ohm resistor. In our week 3 lab session I discovered I didn't have the battery so I used the Raspberry Pi as a power source instead. -Code: +*Code:* ``` import RPi.GPIO as GPIO @@ -15,15 +15,12 @@ GPIO.setup(18,GPIO.OUT) GPIO.output(18,GPIO.HIGH) ``` -<img src="Task1.JPG" width="30%"> - -### I then upgraded the breadboard using the same principles I learnt in the previous task. +<img src="Task1.JPG" width="33.33%"> # Task 3 (3 LEDs) +I added two more LEDs, following the same process as before. Using the GPIO pins, I wrote some code to flash each LED with a `time.sleep(0.1)` (0.1s) delay. I'm also introducing the use of a `while` loop. -<img src="Task2.JPG" width="30%"> - -Code: +*Code:* ``` import RPi.GPIO as GPIO import time @@ -55,35 +52,51 @@ while True: time.sleep(0.1) ``` -Short video: +<img src="Task2.JPG" width="33.33%"> + +#### Short video: +This shows the sequence between the LEDs [](http://www.youtube.com/watch?v=7xLNLzCIo9c) # Task 4 (Using buttons) -Adding the first button: +## Adding the first button +Ensure the buttons work and respond with a console output. + +<img src="Task4.JPG" width="33.33%"> -<img src="Task4.JPG" width="30%"> +<img src="Screenshot 06.10.23.png" width="33.33%"> -Making sure that the button press is registering: -<img src="Screenshot 06.10.23.png" width="30%"> +## Adding the second button +Following the same process as before I added a second button using a different GPIO input. I then created a simple program to detect when either button gets pressed. + +*Code snippet:* +<br> +``` +if (GPIO.input(button_1_pin) == False): + print("Button 1") +if (GPIO.input(button_2_pin) == False): + print("Button 2") +``` -I then added a second button: +<img src="Task4_1.JPG" width="33.33%"> -<img src="Task4_1.JPG" width="30%"> +## Final bit of Python programming for Task 4 +I added 3 blue LEDs, to test they worked correctly I turned them all on using basic GPIO code. -I then readded the 3 LEDs, recreating Task 3. To make sure they all worked I tested them with various GPIO pins +<img src="Task4_2.JPG" width="33.33%"> -<img src="Task4_2.JPG" width="30%"> +<br> -### After I had tested everything I wrote the seqeuncing code using the two buttons and the 3 LEDs +**Testing and implementing the code below it follows the spec you have provided. I've added a short video showcasing it in action!** -Short video: +**Short demo:** [](http://www.youtube.com/watch?v=K9MPf20hbis) -Final code: +*Final code:* ``` import RPi.GPIO as GPIO import time @@ -149,9 +162,8 @@ while True: current_led = 0 ``` -Console logs: +*Console logs:* <img src="Screenshot 06.10.23_2.png" width="30%"> # Task 5 -... \ No newline at end of file -- GitLab