Found 112 Articles for Arduino IDE

Check if a character is a punctuation mark in Arduino

Yash Sanghvi
Updated on 31-May-2021 14:12:55

157 Views

Just like there is a function to check if a character is alphanumeric or not, there is another one to check if a character is a punctuation mark or not. The name of the function is isPunct(). It takes a character as an input and returns a Boolean: true if the given character is a punctuation mark.ExampleThe following example demonstrates the use of this function −void setup() {    // put your setup code here, to run once:    Serial.begin(9600);    Serial.println();    char c1 = 'a';    char c2 = ', ';    char c3 = '1';    char c4 ... Read More

Check if a character is alphanumeric in Arduino

Yash Sanghvi
Updated on 31-May-2021 14:12:30

527 Views

Depending on your use case, you may need to check if a character is alphanumeric or not in Arduino. One example can be validating password strings, wherein you’ve allowed only alphanumeric characters for passwords. Or checking file names for storage in SD Card (sometimes some special characters are not allowed in file names). Arduino has an inbuilt function which checks whether a given character is alphanumeric or not. As you would have guessed, the function is isAlphaNumeric() and it takes in a character as the argument, and returns a Boolean.Examplevoid setup() {    // put your setup code here, to ... Read More

Bitwise XOR in Arduino

Yash Sanghvi
Updated on 31-May-2021 14:12:06

2K+ Views

Just like other bitwise operators, bitwise XOR also applies on the corresponding bits individually.The operator is ^ and the syntax is, a ^ bwhere a and b are the two numbers to be XORed.The truth table for XOR is given below −PQP^Q000011101110As you can see, the XOR operator returns 1 only when the two bits are different.If you perform 10 ^ 3, this is the computation that will happen at the bit level (assuming your board represents integers using 16 bits)00000000000010101000000000000000113000000000000100110 ^ 3 = 9ExampleLet’s verify this on the Serial Monitor. The code is given below −void setup() {   ... Read More

Logical NOT in Arduino

Yash Sanghvi
Updated on 31-May-2021 14:11:41

3K+ Views

Logical NOT is performed using the ! operator. The truth table is given below −ExpressionOutputTFFTAs you can see, the logical NOT inverts the truth value of the expression.ExampleThe usage can be understood from the example given below −void setup() {    // put your setup code here, to run once:    Serial.begin(9600);    Serial.println();    int i = 10;    if (!(i > 10)) {       Serial.println("i is NOT greater than 10");    }    else {       Serial.println("i is greater than 10");    } } void loop() {    // put your ... Read More

Bitwise NOT in Arduino

Yash Sanghvi
Updated on 31-May-2021 14:11:19

771 Views

Unlike logical NOT, which inverts the truth value of an expression, the bitwise NOT applies to each bit of a number and inverts its value (0 to 1 and 1 to 0). The operator is ~.The syntax thus is ~a, where a is the number on which this operator has to apply.Please note, that all the leading 0s in the number’s representation are also converted to 1. For example, if your board uses 16 bits to represent an integer, then here’s what ~10 will look like0000000000001010101111111111110101~10=-11As you can see, each bit of 10 got inverted. This number corresponds to, using ... Read More

Logical AND and OR in Arduino

Yash Sanghvi
Updated on 31-May-2021 14:10:39

11K+ Views

The logical AND is denoted by the && operator, while the logical OR is denoted by the || operator.SyntaxExpression1 && Expression2ORExpression1 || Expression2Where expression1 and expression2 evaluate to Boolean values (true or false). The output of these statements is determined by the truth tables of logical AND and OR.The truth table for AND is given below −Expression1Expression2OutputTTTFTFTFFFFFAs you can see, both the expressions have to be true for the AND statement to output true.The truth table for OR is given below −Expression1Expression2OutputTTTFTTTFTFFFAs you can see, even if one of the expressions is true, the OR statement will output true.ExampleThe following ... Read More

Bitwise AND and OR in Arduino

Yash Sanghvi
Updated on 29-May-2021 14:26:50

1K+ Views

Bitwise AND/ OR means AND/ OR performed at a bit-level, individually. Each number has its binary representation. When you perform the bitwise AND of one number with another, the AND operation is performed on the corresponding bits of the two numbers. Thus, LSB of number 1 is ANDed with the LSB of number 2, and so on.The bitwise AND operation in Arduino is & and the bitwise OR operator is |.Syntaxa & bfor AND.a | bfor OR.The truth table for AND isPQp & q000010100111The truth table for OR is −PQp & q000011101111Since these are bitwise operators, we need to perform ... Read More

Basic analogRead in Arduino Program

Yash Sanghvi
Updated on 29-May-2021 14:27:05

541 Views

Converting analog values to digital is a common requirement from microcontrollers in general, and Arduino is no different. Arduino IDE has a built-in analogRead function to facilitate the conversion of analog values to digital.From the programming perspective, the only thing you require to know is the pins of your microcontroller that support ADC. On the Arduino UNO board, the pins A0 to A5 support ADC.Now, let us assume that you’ve connected your A0 pin to an analog wire (maybe the junction between an LDR and a resistor, or the central leg of a potentiometer).The basic Arduino code to print the analog ... Read More

Exponential expressions in Arduino

Yash Sanghvi
Updated on 29-May-2021 14:28:57

4K+ Views

The pow() function of Arduino can be used for evaluating exponential expressions. Any expression of the form ab can be expressed as pow(a, b). For example 23 becomes pow(2, 3).The type for both the base (a) and the exponent (b) is float. This function returns a double.Examplevoid setup() {    // put your setup code here, to run once:    Serial.begin(9600);    Serial.println();    float base = 2;    float exponent = 3;    Serial.println(pow(base, exponent)); } void loop() {    // put your main code here, to run repeatedly: }OutputThe Serial Monitor Output is shown below −You are ... Read More

Get max and min values of an array in Arduino

Yash Sanghvi
Updated on 29-May-2021 14:29:15

7K+ Views

In order to get the max/ min values of an array in Arduino, we can run a simple for loop. Two implementations are shown below. One uses the max() and min() functions of Arduino, and the other uses the > and < operators.The max and min functions have the following syntax: max(a, b) and min(a, b), and they return the max and min values out of a and b respectively.Implementation 1 − Using > and < operatorsvoid setup() {    // put your setup code here, to run once:    Serial.begin(9600);    Serial.println();    int myArray[6] = {1, 5, -6, ... Read More

Advertisements