This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
user:jparrish:start [2023/12/15 02:34] – [SECTION 2: WRITING AND TROUBLESHOOTING C CODE] jparrish | user:jparrish:start [2023/12/15 04:40] (current) – jparrish | ||
---|---|---|---|
Line 29: | Line 29: | ||
*hg pull - pulls the files pushed into the repository | *hg pull - pulls the files pushed into the repository | ||
*hg update - updates the systems current repository to match the one pulled | *hg update - updates the systems current repository to match the one pulled | ||
- | ==== SECTION 2: WRITING | + | to turn in a project, you must first push it to lab46, then within lab46, run the submit command. |
+ | ==== SECTION 2: WRITING C CODE ==== | ||
In this section, we will be going over the basics of writing, troubleshooting, | In this section, we will be going over the basics of writing, troubleshooting, | ||
==BASIC OVERVIEW== | ==BASIC OVERVIEW== | ||
Line 56: | Line 57: | ||
\n ends a line, and printf allows for text or data to be printed to the terminal\\ | \n ends a line, and printf allows for text or data to be printed to the terminal\\ | ||
finally we can end the code with our return and closing bracket \\ | finally we can end the code with our return and closing bracket \\ | ||
- | <code return(0); | + | <code> return(0); |
} </ | } </ | ||
now we can close the gnu program by doing ctrl+x and then saving changes and naming the file. Before we can run the program, it needs to be compiled.\\ | now we can close the gnu program by doing ctrl+x and then saving changes and naming the file. Before we can run the program, it needs to be compiled.\\ | ||
Line 65: | Line 66: | ||
You can run the program using ./program \\ | You can run the program using ./program \\ | ||
CONGRATULATIONS, | CONGRATULATIONS, | ||
+ | == IF, ELSE, FOR, WHILE, AND LOGIC == | ||
+ | Within C, and most languages, there are different loops and statements you can use to have a function happen conditionally, | ||
+ | If statements are conditional statements that only run if the condition is met | ||
+ | < | ||
+ | code } </ | ||
+ | else statements can be added to run something if the condition isnt met, ifelse also works if you have multiple conditions | ||
+ | < | ||
+ | code | ||
+ | ifelse(condition){ | ||
+ | code | ||
+ | else {code} | ||
+ | </ | ||
+ | While loops work the same, except they run until the condition isnt meant | ||
+ | < | ||
+ | code} | ||
+ | </ | ||
+ | for loops act the same as while, but allows for a change of a value after each iteration of the loop | ||
+ | < | ||
+ | code} | ||
+ | </ | ||
+ | Logic operators are also useful for doing bit manipulation | ||
+ | ^ | ||
+ | ^and|returns 0 if atleast one bit has a 0| | ||
+ | ^or |returns 1 if atleast one bit has one| | ||
+ | ^not|returns the opposite| | ||
+ | ^xor|returns 0 if both bits are opposite| | ||
+ | |||
+ | we can also create our own functions aswell if needed. to do that, we just need to do\\ | ||
+ | < | ||
+ | int RESULT = 0; | ||
+ | RESULT = whatever you want code to do; | ||
+ | return(result); | ||
+ | a library essentially is full of this, which allows us to use functions not in the c language natively. \\ | ||
+ | the last important note is different data types, which are important to know as each have a max size, they are as follows \\ | ||
+ | Signed char- occupies 1 byte of memory or 8 bits, or numbers from -128 to 127. \\ | ||
+ | |||
+ | Unsigned char- same as signed char, but no negatives, 0 to 255 \\ | ||
+ | Signed short int- occupies 2 bytes of memory, or numbers from -32,768 to 32,767.\\ | ||
+ | |||
+ | Unsigned short int-same as signed short int, with no negatives, 0 to 65,535.\\ | ||
+ | |||
+ | Signed int- occupies 4 bytes of memory, or numbers from -2, | ||
+ | |||
+ | Unsigned int- same as signed, but no negatives, 0 to 4, | ||
+ | |||
+ | Signed long int- occupies 8 bytes of memory, from -9, | ||
+ | |||
+ | Unsigned long int- same as signed long int, but no negatives, from 0 to 18, | ||
+ | |||
+ | Signed long long int- occupies 8 bytes of memory, max/min is +-18, | ||
+ | Unsigned long long int- occupies 8 bytes of memory, max is 18, | ||
+ | \\ | ||
==== SECTION 3: HARDWARE AND WIRINGPI ==== | ==== SECTION 3: HARDWARE AND WIRINGPI ==== | ||
- | ==== SECTION 4: PUZZLES ==== | + | Hardware is the most used part of this class, where we typically use LEDS and Wiring pi.\\ |
+ | with wiring pi installed by doing \\ | ||
+ | < | ||
+ | then | ||
+ | sudo dpkg -i wiringpi-latest.deb </ | ||
+ | with wiring pi now installed, we can do some basic things\\ | ||
+ | typing gpio readall into the terminal will spit back the state of all the pins on the gpio board \\ | ||
+ | {{ : | ||
+ | typing gpio write (wpi number) 1 will change the state of the selected pin to 1 or HIGH, type 0 for LOW \\ | ||
+ | gpio mode (wpi number) out will change the pin to output mode, typing in instead will put it into input mode\\ | ||
+ | for any project, youll need the wiringPi library included in your code to make use of wiringPi\\ | ||
+ | \\ | ||
+ | \\ | ||
+ | Within your code, you can use digitalWrite and digitalRead to change the state or read the state of a pin, which is useful for turning an led on and off or checking to see if a button is pressed\\ | ||
+ | < | ||
+ | digitalRead(pin) | ||
+ | </ | ||
+ | if we include softPwm into our libraries, we can also change how much voltage is sent through the pin, instead of High or Low | ||
+ | < | ||
+ | softpwmWrite(pin, | ||
+ | </ | ||
+ | this is useful to make an led breathe or to get different colors in an RGB led\\ | ||
+ | for components, there are far to many to list and explain how they must be wired, instead, one can refer to the wiringPi spreadsheet, | ||
+ | [[https:// | ||
==== SECTION 5: SPREADSHEETS AND TEXT BASED TASKS ==== | ==== SECTION 5: SPREADSHEETS AND TEXT BASED TASKS ==== | ||
+ | This section will show how to install the spreadsheet program and basic functions\\ | ||
+ | firstly, install sc by runnning | ||
+ | < | ||
+ | once sc is installed, you can open files by doing sc (filename)\\ | ||
+ | within sc, there are tons of functions and commands that can be looked upin the terminal with < | ||
+ | But, for the purposes we are using it for, there are only a handful that you should really know \\ | ||
+ | |Q | quit the program | | ||
+ | |= | enter a number that you can use for cell calculation (D4 - D5) | | ||
+ | |/<,> | enter a string center aligned ,left, or right aligned | | ||
+ | |@sum| add all in specified range | | ||
+ | within the course, sc is mainly used for gfo.\\ | ||
+ | |||
+ | |||
- | ==== CLOSING NOTES ==== | ||