This function can write an analog value into an analog output pin mentioned in its argument to generate the equivalent voltage on that pin. This project also monitors the mapped variable’s value before using that variable to generate the analog voltage in an analog output pin. The variable ‘var’ could be of the type integer or character. The above statement will convert the value which is in the range of 0 to 1023 (the output of 10 bit ADC) into the range 0 to 255 (the input range of 8 bit PWM) and stores it in a variable ‘var’. If there is a requirement to directly write the analog input value to the analog output one can make use of the map() function as follows For example the ADC of the arduino generates 10 bit values but the PWM module of the arduino can produce 8 bit equivalent waveforms. The map() is a built-in function which can be used to map the value from one rage to another range. The serial printing functions are then used to print the value of this variable in this particular project. The above statement reads the value from the A0 and stores it in the variable ‘var’. This function is used to enable the built-in ADC of the arduino’s microcontroller which then converts the analog value appears in a particular pin to its 10 bit digital equivalent and then stores in the variable. The values printed after the Serial.println() function will appear on the next line in the window. The function Serial.println() is also used in the same manner but to introduce a new line and carriage return after printing the value in the serial monitor. In short the Serial.print() function actually ‘prints’ the value which is given as a parameter to it on the serial monitor. For example if the variable ‘var’ has a value 10, then it can be displayed on the serial port as 10 using the following statement This function formats the value to ASCII characters so that it can be displayed in the serial monitor window. The Serial.print() function is used in the code to send the value to the serial port that has to be monitored. ![]() ![]() This function is used in the code to initialize the serial port with the baud rate 9600 which is given as the argument of the function and also with 8 bits of data frame, one start bit, one stop bit and no parity bits using the statement given below This project also make use of the serial port accessing functions explained in the projects on how to receive and send serial data using arduino and how to do serial communication using arduino. ![]() It is assumed that the reader has gone through the project Getting started with Arduino and tried out the project on how to use the analog input and output of the arduino. 4:External USB to TTL converter board for programming Arduino and serial communication
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |