User Tools

Site Tools


notes:c4eng:fall2023:projects:ptb1

PTB1

GRABIT

After you've made a directory for ptb1 on lab46, you can use the grabit command to acquire the source code that we'll be modifying in this project, like so:

grabit c4eng ptb1

This will populate the ptb1 directory with all source files that you'll need for this project.

It's important to note, that while you'll be grabbing the source files via lab46, the required dependencies will not be available there and you will have to retrieve these files from your pi.

You can push these source files from your repository using the following set of commands:

hg add * 
hg commit -m "YOUR COMMIT MESSAGE HERE" 
hg push 

Assuming you've encountered no errors, you should now be able to retrieve these files on your pi:

hg pull 
hg update

PARTS

LED bar

The LED bar is a rather simplified version of putting 10 LEDs on your breadboard. The LED bar contains 10 different LEDs that require their own GPIO pins and resistors. Each gpio pin needs to be set to output mode. You can connect your resistors from one leg of the LED directly to the “-” column on the side of the bread-board to save some space. If your LED bar is not working, you can try flipping it around because the direction of the flow matters, just like regular LEDs.

button

each button should be wired the same way, just to different pins. each button needs a 3.3v ran through a 10Kohm resistor and a ground wire, with a final wire with a 10kohm resistor to a gpio pin. Within wiringpi, the pin must be set to input mode. The gpio wire should also be on the opposite side of the 3.3v wire and the ground wire. You made need to switch which pin your wires are connected to if your button is not working properly. You can also check if the button is working by looking at the gpio readall table before and after the button is being pressed, and you should see a change in voltage for that gpio pin (reminder to change voltage first gpio mode “pin” out, then gpio write “pin” 1).

LOGIC

Synopsis: To achieve our desired outcome with only one if statement, we'll need to implement bit shifting and a for loop. It would also be helpful, first, to create an array if our pins are not connected sequentially.

ARRAYS IN C

To declare an array in C is similar to declaring any variable: we declare the data type (in arrays, the data type of all the elements), name the variable, and assign a value (or a matrix of values for arrays).

 
int myArray[10] = {5,2,22,6,...}; 

In our sample, 10 is the number of elements we have (not shown).

notes/c4eng/fall2023/projects/ptb1.txt · Last modified: 2023/10/19 02:54 by mwinter4