An open API service indexing awesome lists of open source software.

https://github.com/tempehs/micropython_oop_mini_project


https://github.com/tempehs/micropython_oop_mini_project

Last synced: about 1 year ago
JSON representation

Awesome Lists containing this project

README

          

# TODO

- Test and refine buzzer
- Controller class
- Implement state machine in controller class
- Refine variables, methods and class names
- Add documentation

# Learn MicroPython Raspberry Pi Pico

This repository is a mini OOP based project to explicitly teach Object Oriented Paradigm programming concepts specifically in the microcontroller context.

Students will be recreating a model of the pedestrian crossing on Unwins Bridge Road out the front of Tempe High School.

![A street view image of the system we will be modeling](/images/real_world_situation.png "The traffic lights, pedestrian warning lights, pedestrian button and control system.")

From the above real world control system we will model:

- Overloading and overriding polymorphism
- Inheritance, multilevel inheritance and multiple class inheritance
- Abstraction
- Decomposition and composition
- Generalisation
- Encapsulation
- Object instantiation, objects as instance variables

## Wire your system

![A prototype of the model](/images/prototype_model.png "Use the below components to wire this model.")

### Components

- Breadboard
- Momentary switch
- 5x LED
- 1x Piezo buzzer
- 5x 220Ω resistors
- Jumper leads
- Pi Pico

### Pin allocation

| Pin | |
| ---- | -------------------- |
| GP3 | Red LED |
| GP4 | Keyboard Interrupt |
| GP5 | Amber LED |
| GP7 | Red LED |
| GP17 | Flashing Green LED |
| GP19 | Flashing Red LED |
| GP22 | Button signal |
| GP27 | Piezo Buzzer |
| GND | Circuit Ground |
| 3V3 | Button logic voltage |

## UML Diagram

```mermaid
classDiagram
PIN <|-- Button : Inheritance
PIN <|-- Led_Light : Inheritance
PWM <|-- Buzzer : Inheritance
Led_Light <|-- Flashing_Light : Inheritance
Buzzer <|-- Flashing_Light : Inheritance
Button --* Pedestrian_Crossing : Composition
Led_Light --* Pedestrian_Crossing : Composition
Flashing_Light --* Pedestrian_Crossing : Composition
class PIN{

}
class Led_Light{
obj Servo
get_pos()
set_rot_cw(count)
set_rot_ccw(count)
}
class Flashing_Light{
obj Servo
int start_angle
int min_set_angle
int max_set_angle
get_angle()
set_angle(angle)
}
class Button{
obj Servo
int open_angle
int closed_angle
bool claw_state
set_open()
set_closed()
get_state()
}
class Pedestrian_Crossing{
obj Claw
obj Base
obj Elbow
obj Elbow
pick_cube()
place_cube()
}
```

> [!Note]
> Inheritance and association labels are note required in a UML diagram but have been added for understanding.

## Versions

| Version | Notes |
| ------- | ------------------------------------------------------------------------------------------------------------------------- |
| v01.py | Basic "Blink" Program (the Hello World of mechatronics). |
| v02.py | Test wiring and use basic methods from parent `Pin` class. |
| v03.py | Implement a child class of MicroPython `Pin` class for the traffic lights, demonstrating Inheritance and Polymorphism. |
| v04.py | Move the `Led_Light` class to a separate file, demonstrating abstraction. |
| v05.py | Write a `Button` class and test it by instantiating it and controlling the `red_light` instance of the `Led_Light` class. |
| v06.py | Implement a Event Trigger for when the button has been pressed. |
| v07.py | Demo code only of Multiple Inheritence. |

TempeHS Pi Pico Boilerplate
by Ben Jones is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International