## 1. Increment and Decrement

An increment and decrement operator is an arithmetic operator that is used to increment or decrement an integer variable by a value of one. We look at how to use this operator in this part of the Sketch code programming with Arduino IDE below.

## 2. Operator Precedence Sketch Test Code

Practically every sketch code uses mathematical operators to manipulate the value of variables. This example provides a brief overview of the most common mathematical operators. Moreover, if we will not explicitly state the order in which an expression is considered, this will be evaluated based on the operator precedence. For example, in 3+6*9, the 2 first will be multiplied by 9 and then the result will be added to 6 because the ( * ) has higher precedence than the ( + ). However, to avoid ambiguity in the program, it is advised that the statement be written as 3+(9*8). The order of evaluation is controlled through the placement of parenthesis in the code syntax. Here is the table of the operator’s precedence listed below. The highest precedence is at the top of the list and the lowest is at the bottom.

• Muliplicative : * / %
• Relational : <> <= >=
• Equality: == !=
• Logical AND: &&
• Logical OR: ||
• Assigname: = += -= *= /= %=

## 3. Modulo Test Sketch Code

The modulo ( % ) operator will return the remainder of a number divided by another additionally it is often used to keep the values within a range of the set.

## 4. Sine / Cosine Test Sketch Code

SINE – sin() & COSINE – cos(). This number between 0 and PI*2 – TW0_PI which is approximately 6.28 are placed into these functions and numbers between -1 and 1 are returned.

## 5. Random Test Sketch Code

Each time the code is executed the result value is different, it will generate pseudo-random numbers. In addition, the syntax is used as random() / Random(max) / random(min, max).

## 6. Interrupts Test Sketch Code

An interrupt is a signal provided by the hardware or software when a process or event needs immediate attention. It alerts the processor to request a priority method needing interruption of the current process. most SOCS and MCU’s IO has a dedicated pin for this purpose and it is called the Interrupt Service Routing or ISR pin. For example, case, when your car is running, and your can ECU / Microcontroller is busy sensing the speed of your car, requesting other sensor’s data, controlling an AC, Fuel Status, Engine Temperature, and so on. however, your car suddenly hit a roadblock then an accident happened! At this time controller stops all the process and send a signal to deploy an airbag. This is the rule of the interrupt signal, it is used as a very high priority for all. There are 2 types of interrupts, Hardware Interrupts and Software Interrupts – hardware interrupts occur in response to an external event, which is the state your IO pin turns to HIGH or LOW. Software interrupts are instructions to the hardware interrupts.

## 7. Timer Sketch Test Code

A timer is similar to an interrupt and a simple clock that can measure time intervals of an event cycle, all MCU (Microcontrollers) have a built-in clock called an oscillator, for example, the ATMEGA328P currently it has 16Mhz which means it has a response speed at 16Mhz, the higher the clock frequency the higher will be the processing speed. A timer uses to counter which counts at a certain speed depending upon the MCU clock speed frequency. For most MCU it takes 1/16000000 seconds or 62 Nano Seconds to make a single count. in other words, an MCU moves from one instruction to another instruction every 62 nanoseconds.

## 8. Serial Read & Write Test Sketch Code

Serial is used for communication for all types of microcontroller boards especially Arduino boards to speak and talk to your computer or other devices. All the most popular microcontroller development boards have at least one serial port also known as a UART or USART. Serial.read() is a function that reads incoming serial data transmission, hence Serial.write() writes binary data to the serial port and sent as a byte or series of bytes; to send the characters representing the digits of a number use the print() function.

8 Useful Math Coding in Sketch Code for Starters
Tagged on:    