In our trainings in this section, we will switch to the C programming language, which is frequently used in coding processes.
The information to be explained here; It is an introduction to coding on Arduino. In our training, the most basic information is given in order to understand the C programming language that we will use in robot projects on arduino.
Let’s take a look at how C coding is done on arduino.
HIGH and LOW and PinMode arduino encoding Expressions
Logical expressions are used in Arduino to show whether expressions are true or false. Project “false” and “true” to screen “false” written in lowercase is expressed as 0. “true” is expressed as 1. In Arduino, capital letters HIGH and LOW are used to define Pin levels. In other words, we can express the situation here simply as follows for those who do not actually have basic coding knowledge. Just as we use an on-off button to turn on the lamp in the house when we need it, the HIGH and LOW statements here act like the on-off button here. When we press the button to turn on the lamp, that is, like the expression used in the coding, the HIGH statement comes into play to energize the lamp and turns on the lamp, when we press the lamp off button, the energy is cut off, the LOW statement is activated and the lamp turns off.
PinMode Definition and Usage;
We can define the pins on the Arduino board as inputs or outputs. Input pins, namely those defined as INPUT, generally function as on/off buttons. Those defined as output, ie OUTPUT, are generally used for LED circuit elements. These pins must be defined in the Setup function, which we have seen in previous trainings.
Examples for PinMode code;
pinMode(5,OUTPUT); (Indicates that pin 5 on the Arduino is the output pin) digitalWrite(5,HIGH); (Indicates that digital pin 5 on the Arduino is open) In the pin definitions, we can choose input and output what the entered pin will be. There are analog and digital pins on Arduino. The coding process was carried out by selecting the digital pin number 5 from these pins. We need to tell the arduino what to do with this chosen pin 5, with coding; Let the arduino perform an action according to the coding we have done. The definition of pinMode(5, OUTPUT) that we will use frequently when coding Arduino; functions as output since digital pin No. 5 Output is written in PinMode on the encoding line. Therefore, our output pin becomes pin 5. In the pin definitions, we can choose what the entered pin will be as input and output. In the DigitalWrite statement, the pin is specified and the information whether the pin is on or off is created with the coding line. digitalWrite(5,HIGH); when we define it as; Energy output is provided on pin 5. If this energy output is wanted to be stopped, if LOW is written instead of HIGH, the energy flow stops. In the analogWrite expression, the selected pin generates PWM signals on it. This connected pin can adjust the brightness of the adjustable LED with PWM signals. Unlike digital pins, analog pins produce signals that will gradually increase and decrease the brightness of the LED. Our next training topic; It is about what the constants in the C language used in Arduino coding are and what they are used for.
robottrainings.com