User Tools

Site Tools


notes:c4eng:fall2024:projects:ptb1

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
notes:c4eng:fall2024:projects:ptb1 [2023/10/19 02:54] – created - external edit 127.0.0.1notes:c4eng:fall2024:projects:ptb1 [2024/10/21 23:12] (current) – [ARRAYS IN C] dprado
Line 2: Line 2:
  
 =====GRABIT===== =====GRABIT=====
 +Log into your student account and proceed to the c4eng file:
 +Enter your username and password
  
-After you've made a directory for ptb1 on lab46, you can use the <wrap hi>grabit</wrap> command to acquire the source code that we'll be modifying in this project, like so: +"cd" into c4eng with the command:
-<code> +
-grabit c4eng ptb1 +
-</code> +
-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. +user@lab46:~$ cd src/fall2024/c4eng
  
-You can push these source files from your repository using the following set of commands:  +type grabit, followed by c4eng ptb1 to pull the project from the server
-<code> + 
-hg add *  +user@lab46:~/src/fall2024/c4eng$ grabit c4eng ptb1 
-hg commit -m "YOUR COMMIT MESSAGE HERE"  + 
-hg push  +Enter into the ptb1 file. If you're using a raspberry pi, enter into the wiring_pi file. If you're using a pico, enter into the pi_pico file. 
-</code> +Access the ptb1.c file and alter accordingly. 
 +=====REPO STEPS=====
  
-Assuming you've encountered no errors, you should now be able to retrieve these files on your pi:  
-<code> 
-hg pull  
-hg update 
-</code> 
 =====PARTS===== =====PARTS=====
  
 ====LED bar==== ====LED bar====
-The LED bar is a rather simplified version of putting 10 LEDs on your breadboardThe LED bar contains 10 different LEDs that require their own GPIO pins and resistors. Each gpio pin needs to be set to output modeYou can connect your resistors from one leg of the LED directly to the "-" column on the side of the bread-board to save some spaceIf your LED bar is not workingyou can try flipping it around because the direction of the flow matters, just like regular LEDs+The raspberry pi electronics kits came with small, lego-sized, rectangular prism-shaped bars containing 10 independent LED lightsThese LED lights are not connected in series or parallel, and each light must be individually wired in order to properly functionThe LEDs appear to be red, and the entire bar fits nicely right on the raspberry pi breadboard and occupies 10 adjacent rows. In stl2, we used these bars to create 8 or 10-bit binary countersIn this projectwe are using these same bars to create another binary counter, but now we are adding buttons to reverse the order of the lights and begin counting down from the highest number possible
 ====button==== ====button====
-each button should be wired the same wayjust to different pinseach 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). +similar to how we used the buttons in ptb0we will need to find 2 buttons in our electronics kit which look like little squares with 4 small legs from each cornerTo allow for the button to output and give reading we need to physically hook the button up correctly. You do this by hooking one leg of the button to a direct line to ground. Then, another leg to 3.3v power through a 10 kΩ resistor and a final leg to a gpio pin through another 10 kΩ resistorOnce you have connected this button correctly you can then initialize it to a wpi pin value in the code before using the button. You will need to repeat these steps with another button as for ptb1 you will need 2 seperate buttons one for increasing count and on for decreasing count.
 =====LOGIC===== =====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===== =====ARRAYS IN C=====
 +a data structure that allows you store multiple elements of the same data type in the same memory location. Arrays can contain many different date types and even other date structures. Once an array is initialized, it's size cannot be changed. However, you can change date elements at specific points in the array. 
 +
 +     int numbers[5] = {1, 2, 3, 4, 5};  //declares and creates an array that contains 5 integers 1,2,3,4,5
 +
 +     int thirdNumber = numbers[3];  //access 3rd data element in the array, which would be 3 in this case.  
  
-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).  
  
-<code>  
-int myArray[10] = {5,2,22,6,...};  
-</code> 
  
-In our sample, 10 is the number of elements we have (not shown). 
notes/c4eng/fall2024/projects/ptb1.1697684072.txt.gz · Last modified: 2023/10/19 02:54 by 127.0.0.1