User Tools

Site Tools


Sidebar

content

user:jparrish:start

This is an old revision of the document!


C for Engineering End of Year Summarization

This guide serves as an overall summary of the topics learned and discussed during the semester, all information is sorted into three categorize, not necessarily by date taught


SECTION 1, USING A NAVIGATING IN THE TERMINAL

This guide only covers use in the PiOS, linux and WindowsOS. For Mac OS, consult a mental health specialist

Generally, you will have access to an operating system, which will both organize information and present it in a user friendly manner. However, there are instances, especially in this class, that will require the use of the terminal. The terminal, also known as the command prompt on windows, serves as the main connection between you and the computer. It allows you to navigate files and folders, run programs or scripts, remote into other systems or connections, and a whole variety of things. Opening the terminal is different on every OS, but is generally similar.
WINDOWS OS– Press WINDOWS+R, this will open up the run prompt, then type “CMD”. The command prompt should be open
LINUX/PIOS– Navigate to APPLICATIONS, then click and run the TERMINAL application
With the terminal view open, we now have access to an array of commands, these commands, with examples, are as follows:

cd - used to navigate into a directory (folder) or sub directory. cd .. can be used to exit the directory
cd src/fall2023 will go into the src directory and then into the fall2023 subdirectory within it
ls (dir on windows) - used to see the subdirectories and files or programs in the directory you are currently in.


cat - looks into a directory or file
mkdir - makes a directory
nano - creates a text file with name mentioned, or edits text file
rm - removes a directory or file
./ - runs a program
sudo - runs the following command with admin permissions
gcc - compiles a C program
ssh - allows for remote connection to a server, or another device
hg - prefix for all repository commands, which include:

  • hg add - adds files in directory to repository
  • hg commit - commits the added files to the repository with a message for why they are there
  • hg push - pushes commited files to the repository to be added to another system
  • hg pull - pulls the files pushed into the repository
  • hg update - updates the systems current repository to match the one pulled

SECTION 2: WRITING AND TROUBLESHOOTING C CODE

In this section, we will be going over the basics of writing, troubleshooting, and compiling C code, aswell as basic functions and basic programs that are either useful, or a good refresher.

BASIC OVERVIEW

C code has a structure that should typically be followed, if you want a program to be compiled. Since the computer reads code in the same order we do, generally code is structured like this:

libraries
variables and definitions
int main
return
function definitons 
THE BASIC HELLO WORLD PROGRAM

To begin, a text file will be needed. We can either create it in the terminal using the NANO command, or we can use a text editor to write the code instead. In this section, however, we will assume you are using the terminal. The file extension should be .c to decern that it is indeed C code.

 nano program.c 

We now should be within the GNU text editor. We can now write our code. For this example, we are going to be writing a basic hello world script. However, there will be a list of other basic functions, aswell as a list of definitions, and more wiring pi orientated code in section 4.
The first lines with our code should be our libraries. Libraries allow the computer to look into another file for definitions of certain functions not built into the kernel or into the language. For example, to control a servo, you would use the servo.h library, or you could create all the functions and calculations yourself.
to include a library, use the #INCLUDE line. Within GNU, the text will turn a different color, then write the name of the library used. In this example, we need the stdio.h library, thus we need to write,

 #include stdio.h 

This is the only library we are going to need for this program, so we move on to declaring variables.
in this example, no variables are needed, so we can skip writing

SECTION 3: HARDWARE AND WIRINGPI

SECTION 4: PUZZLES

SECTION 5: SPREADSHEETS AND TEXT BASED TASKS

CLOSING NOTES

user/jparrish/start.1701784610.txt.gz · Last modified: 2023/12/05 13:56 by jparrish