Arduino Programming Language Articles

Page 6 of 10

Suspend/Resume tasks in FreeRTOS using Arduino

Yash Sanghvi
Yash Sanghvi
Updated on 29-May-2021 1K+ Views

If you wish to suspend a task in FreeRTOS, there is a function vTaskSuspend() that can be used. The syntax is −Syntaxvoid vTaskSuspend( TaskHandle_t xTaskToSuspend );As you can see, it takes the handle of the task to suspend as the argument and returns nothing. A suspended task can be resumed using vTaskResume(). The syntax is −Syntaxvoid vTaskResume( TaskHandle_t xTaskToResume );This again takes the handle of the task to be resumed, and returns nothing.In order to see an example, we will walk-through the code given in −https://exploreembedded.com/wiki/Task_Suspend_and_ResumeAs you can see, four Task handles are declared initially, and the tasks are created in the ...

Read More

How to increase the font size of text in Arduino IDE?

Yash Sanghvi
Yash Sanghvi
Updated on 29-May-2021 1K+ Views

The default font size of Arduino IDE can be a bit too small for some developers. In order to increase the font size, go to File → Preferences.In the dialog box that opens up, change the value of Editor Font size. The default value is 12. You can set it to a value you are comfortable with.Click OK and the changes will reflect on your IDE immediately.

Read More

How to show line numbers in Arduino IDE?

Yash Sanghvi
Yash Sanghvi
Updated on 29-May-2021 3K+ Views

Line numbers are often necessary when working with large files consisting of several functions. Most developers prefer to have the line numbers shown in their code editing software.By default, line numbers are hidden in the Arduino IDE. In order to display the line numbers, go to File → Preferences.In the dialog that opens, tick the box that says ‘Display Line Numbers’.The line numbers will now appear on the Sketch.Alternatively, the line number of your cursor can always be obtained from the bottom-left corner of the screen. This is one of the not-so-well-known features of Arduino IDE.

Read More

Arrays in Arduino

Yash Sanghvi
Yash Sanghvi
Updated on 02-Apr-2021 5K+ Views

Declaring an ArrayIn order to declare an array, you follow the syntax give below −Syntaxtype array_name[array_size];Exampleschar buf[500]; int new_array[200];Accessing elements of the arrayThe array element numbering starts from 0. The element can be accessed by specifying the index of the element in square brackets against the name of the array. For instance −int second_element = new_array[1];Getting length of arrayThe length of the array can be accessed using the sizeof() function.For example, int buf_len = sizeof(buf);Please note that the sizeof() function returns the number of bytes, and not the number of elements. If you have an int array, and int is ...

Read More

Timer Interrupts in Arduino

Yash Sanghvi
Yash Sanghvi
Updated on 24-Mar-2021 4K+ Views

As discussed in another article, Timers are basically counters. When they reach the end of the count, they overflow. We can use this event to generate an interrupt. Now, the traditional way of generating the interrupts in Arduino involve changing a lot of registers. Luckily, we have libraries for making our lives easy.We will use the TimerOne library for generating interrupts on Timer1. Similarly, there is the TimerThree library for generating interrupts on Timer3 (not applicable for Arduino Uno).Go to Tools -> Manage Libraries and search for TimerOne and TimerThree (optional) and click Install.Next, import the library in your code ...

Read More

Timers in Arduino Uno

Yash Sanghvi
Yash Sanghvi
Updated on 24-Mar-2021 10K+ Views

As discussed earlier, Arduino Uno has 3 timers: Timer0, Timer1 and Timer2. Timer0 and Timer2 are 8-bit counters (they count from 0 to 255), while Timer1 is a 16-bit counter (it counts from 0 to 65535). Internally, Timer0 is used for the millis() function, and therefore, it is recommended not to mess with it. You can use Timer1 and Timer2 for your custom requirements.Note that the clock frequency of Arduino Uno is 16 MHz. Therefore, no timer can have intervals shorter than (1/16000000). However, for most applications, you would want longer intervals (lower frequencies). In other words, you would want ...

Read More

Timers in Arduino

Yash Sanghvi
Yash Sanghvi
Updated on 24-Mar-2021 2K+ Views

Every microcontroller has one or more timers that help the users perform tasks at precise intervals. Arduino Uno, for example, has 3 timers: Timer0, Timer1 and Timer2. Other boards may have the same or different number of timers, which you can find from the datasheet of that board/ microcontroller. What are timers?Timers are essentially counters. Let me give you a simple example. Say you want to trigger a task every 5 seconds. Now, if you have a counter which can count from 0 to 255, then if you somehow adjust the rate of counting such that it finishes counting exactly in ...

Read More

Difference between float and double in Arduino

Yash Sanghvi
Yash Sanghvi
Updated on 24-Mar-2021 7K+ Views

FloatFloating point numbers are stored using 4 bytes (32 bits).Their max value can be 3.4028235E+38 and their min value can be -3.4028235E+38.They have a precision of about 6-7 decimal places.DoubleWhile on several platforms, double has more precision than float. However, on most Arduino boards (Uno and many other ATmega boards), double has the same size as float. Arduino Due is an exception, wherein double has a size of 8 bytes (compared to 4 bytes of float).On the boards where double is stored using 8 bytes, the max value can be 1.7*10^308 and the min value can be -1.7*10^308. On the ...

Read More

Difference between signed and unsigned integer in Arduino

Yash Sanghvi
Yash Sanghvi
Updated on 24-Mar-2021 2K+ Views

When you define an integer, it is signed by default. In other words, it can accept both positive and negative values. Unsigned integers, as the name suggests, accept only positive values. Therefore, they have a higher range.If you are using a board that uses two bytes (16 bits) to represent an integer, then the maximum range you would get for an unsigned integer is 0 to 65535 (216-1).However, when representing signed integers, the range would be -32767 to +32767. Note that 32767 corresponds to (215 -1). As you can see, the most significant bit seems to be out of action. ...

Read More

Defining new functions in Arduino

Yash Sanghvi
Yash Sanghvi
Updated on 24-Mar-2021 317 Views

Defining new functions in Arduino is equivalent to defining the functions in C.The syntax is −Syntaxreturn_type function_name(arg_type arg)The only difference is that in C, the function needs to be declared at the top, if it is invoked before its definition. No such constraint exists in Arduino. The following code demonstrates this −Examplevoid setup() {    Serial.begin(9600);    Serial.println(); } void loop() {    // put your main code here, to run repeatedly:    for (int i = 0; i < 10; i++) {       long int w = square(i);       Serial.println(w);       delay(1000);   ...

Read More
Showing 51–60 of 99 articles
« Prev 1 4 5 6 7 8 10 Next »
Advertisements