User Tools

Site Tools


user:lbond1:start

C4ENG TOPICS SUMMARY

Liam Bond

abc0

Our very first project went over a lot of starting concepts like making directories, and creating and editing text files. It also required setting up the repository with the fixrepo command. After the repository is also set up on another device with the hg clone command, the following hg commands can be used to update and save what is being worked on. If you want to update recently changed files and push them onto another device, use the following:

hg add
hg commit -m"commit message"
hg push 

Then, go on your other device, use the following to pull onto that device:

hg pull
hg update

This project also went over concepts like making files and directories. Directories can be created with the mkdir command, and text files can be made and edited with the nano command, and viewed with the cat command. If the file is a .c file like hello.c, and there is a Makefile in the directory, then it can be compiled with the make command and run with ./hello. For a regular project that already has the Makefile, the following commands can be used to go into that directory, edit the file, and make and run the program:

cd src/fall2023/c4eng/abc0
nano hell0.c
make
./hello

gtf0

gtf0 (graphics to figure out)involved editing code that displayed different shapes and colors. Each color was defined to have a certain hexadecimal value. For example, blue was defined with the following line:

blue = gdImageColorAllocate (Image, 0x00, 0x00, 0xFF); 

Other functions like “gdImageRectangle” and “gdImageArc” can be used to create rectangles and circles by putting in the starting and ending x and y coordinates. “gdImageFill” can also be used to fill in that shape.

Different number bases

The base that we are used to, base 10, has 10 symbols (0-9), and after the number 9, it starts over again in the next place as 10. However, other bases including binary (base 2), octal (base 8), and hexadecimal (base 16), also exist and can be more useful when it comes to programming. Computers often use bitwise logic in binary to make computations, since binary only consists of ones and zeroes. Something can also be represented as a binary value in code by typing “0b” brfore the number (0b1111). Hexadecimal has 16 symbols (0-F are commonly used), and as seen in gtf0, RGB values of colors are often represented in hexadecimal, with “0x as the prefix (0xFF). Math also works slightly differently in other bases. In hexadecimal, 9+1=A (10 in base 10), and F+1=10 (16 in base 10), so this has to be kept in mind when certain computations are being done.

dtr0

dtr0 (data type resources) goes over different data types, including signed char, unsigned char, signed short int, unsigned short int, signed int, unsigned int, signed long int, unsigned long int, signed long long int, unsigned long long int. Each data type has different sizes and the maximum and minimum values that can be represented vary for each one. These values were diplayed using the fprintf function. The following line of code was used to display the size of the unsigned char:

 fprintf (stdout, "total size in bytes: %llu\n", size); 

What is typed in the quotes is what is displayed when the program is complied and run (with make and ./dtr0), and the ”%llu“ displays the size as an unsigned long long int.

stl

The stl (seeing the light)projects are the first ones that use the wiringpi, and the breadboard. After a circuit is made and hooked up to the pi (which has the wiringpi installed), the program being run will affect which gpio pins are on and off. The gpio readall command can be used to view the values and the voltages of the gpio pins, and will indicate whether they are set to input or output. A pin can be set to output or input with the pinMode function. The digitalWrite function can be used to change the voltage to high or low, to turn the LED on or off. stl1 also introduces if statements and else statements. If statements can be used to do something only when certain requirements are met. An else statement can be added to an if statement to do something else if those requirements are not met. An if else can be used to do something if a requirement is met, different from the first if statement's requirement, which was not met. These functions can be used together to turn of and on different LEDs under different circumstances. The following if statement was used to turn on a specific LED when there was a 1 in the ones place:

if ((i&0b0001)==0b0001) {
digitalWrite (ones_place, HIGH);
}

The numbers did not need to be defined as binary values, but it might make it easier to tell which number corresponded to which place. The condition also uses ”&“ which is a bitwise and. The result of a bitwise and for any place is 1 if there was a 1 in that spot for both numbers (1111&0001=0001), so using a bitwise and with 0001, can be used to check if there is a one and that spot, and if there is, that LED will be turned on. These were all used together to make the LEDs count in binary.

gfo

The gfo (grade figure outer)projects involved using the sc spreadsheets to show the grades of each portion of the class grade. Spreadsheets are different from regular text files, as “sc” is used to view and edit the spreadsheet. “Q” is also used to exit and “P” is used to save the spreadsheet. To type text in certain boxes, ”<“ or ”>“ need to be used before putting in the text to leftbound or rightbound the text. To type in a number or an eqaution ”=“ has to be used beforehand. “X” can also be used to delete a cell. The spreadsheets can be a helpful tool in organizing information, like class grade, but they work very differently from text files.

ptb

The ptb (pressing the button) projects involved inputing buttons to change the output of the code. After a button is defined to a wiringpi pin, it can be set to input mode. To use the button for if statements, the state of the button can be read with the digitalRead function. to achieve this, the following lines of code can be used:

 pinMode (BUTTON, INPUT);
pullUpDnControl (BUTTON, PUD_UP);
state = digitalRead (BUTTON);

Since state was already defined as an int (int state = 0;), the state can be used in an if statement to do a certain thing, if the button's state is either high or low. To use this in conjunction with the speaker, which uses the softToneWrite function, the following lines of code can be used:

if (state == LOW) {
softToneWrite (SPEAKER, TONE);
} 

This if statement turns the speaker on to the predefined tone, only if the button is being pressed. gpio readall can also be used to check the voltage of a button when it's pressed to see whether it should be high or low in the if statement. The button can also be used with other components like the LED bar, which has 10 LEDs, and the multicolor LED, which uses functions like softPwmCreate and SoftPwmWrite to display different colors depending on the hexadecimal value. Ptb2 also uses a switch, which works just like a button, but stays in the state that it was set to. The switch can be used with the buttons to make the buttons do something different when pressed, depending on if the switch is on or off.

eap

The eap projects (explore a project) involved testing out a new component in the electronics kit. I chose to test out the seven segment display, which can be used to display different symbols. By building off of the sample code from the electronics kit tutorial, what is displayed on the seven segment display can be altered to function in different ways. In other projects like this one, a delay is often included so that everything doesn't just happen all at once. With the use of a button, this delay can be used to slow it down, so the seven segment display counts at a different speed. The following code can be used to change how long the delay is when a button is pressed (when the button is already set to input):

state= digitalRead (slowbutton);
if (state == LOW) {
time = time+100;
}
delay (100+time);

A large variety of things can be done with buttons and switches to affect other components, and this is one example. You can have variables change when a button is being pressed, or have those if statements inside an if statement for a switch being on, so that it only takes affect when that switch is on, and does something else when the switch is off. These components can be built off of to do more complex things like having LEDs count in binary, or display desired color values when a certain thing happens. A variety of different functions can be done when the right code is used.

user/lbond1/start.txt · Last modified: 2023/12/12 17:21 by lbond1