This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
notes:c4eng:fall2024:projects:ptb1 [2023/10/19 02:54] – created - external edit 127.0.0.1 | notes: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 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. | + | user@lab46:~$ cd src/ |
- | 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 |
- | < | + | |
- | hg add * | + | user@lab46: |
- | 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. |
- | </ | + | 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: | ||
- | < | ||
- | hg pull | ||
- | hg update | ||
- | </ | ||
=====PARTS===== | =====PARTS===== | ||
====LED bar==== | ====LED bar==== | ||
- | The LED bar is a rather simplified version of putting | + | The raspberry pi electronics kits came with small, lego-sized, rectangular prism-shaped bars containing |
====button==== | ====button==== | ||
- | each button should be wired the same way, just to different pins. each button | + | similar to how we used the buttons in ptb0, we will need to find 2 buttons in our electronics kit which look like little squares with 4 small legs from each corner. To allow for the button |
=====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, | ||
+ | |||
+ | 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]; | ||
- | 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, | ||
- | </ | ||
- | In our sample, 10 is the number of elements we have (not shown). |