CMPT401_TWU

Lab Report 1 - LED’s and Push Buttons

Jonah Watts

Table Of Contents:

  1. Project 1.1
  2. Project 1.2
  3. Project 2.1
  4. Project 2.2
  5. Assignment Project #1
  6. Assignment Project #2

Tutorial Document:

Project 1.1:

Gif of Program in Action:

Photo of environment:

Project 1.2:

Gif of Program in Action:

Project 2.1:

Gift of Program in Action:

Photo of environment:

Project 2.2:

Gif of Program in Action:

Photo of environment:


Assignment Project #1

Task Description:

To create a program that will flash the LED’s in order of Red, Green, Blue.

Hardware Components:

Circut Diagrams

Photo(s) of the breadboard:

Source Code

The Source code can be downloaded here here

#---------------------------------------------------------
# Jonah Watts 
# Assignment 1, Project 1
# For CMPT 401
#---------------------------------------------------------
from time import sleep_ms
from machine import Pin

#Setup the LED Diodes for the pin in and outs
ledRed=Pin(19,Pin.OUT)
ledGreen=Pin(18,Pin.OUT)
ledBlue = Pin(5,Pin.OUT)

try:
    while True:
        #Rotate between red, green, and blue
        ledRed.value(1)
        sleep_ms(1000)
        ledRed.value(0)
        ledGreen.value(1)
        sleep_ms(1000)
        ledGreen.value(0)
        ledBlue.value(1)
        sleep_ms(1000)
        ledBlue.value(0)

except:
    pass

Gif of program in action


Assignment Project #2:

Task Description:

The goal of this project is to create a system that has two push buttons and an LED. The LED will be turned on by one button, and only one button. The other button will turn the LED off, and that is all.

Hardware Components

Circut Diagrams

Photo(s) of the breadboard

Source Code

The Source code can be downloaded here here

#---------------------------------------------------------
# Jonah Watts 
# Assignment 1, Project 2
# For CMPT 401
#---------------------------------------------------------
import time
from machine import Pin

# First set up the pins
led = Pin(0, Pin.OUT)        
button1 = Pin(14, Pin.IN,Pin.PULL_UP)
button2 = Pin(12, Pin.IN,Pin.PULL_UP)

# If one button is clicked, turn on the LED, if the other one is clicked, turn it off
while True:
    if not button1.value():
      led.value(1)
    if not button2.value():
      led.value(0)

Gif of program in action