Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:introductiontoembeddedprogramming2:cppfundamentals:analog_io [2023/11/21 22:25] pczekalskien:iot-open:introductiontoembeddedprogramming2:cppfundamentals:analog_io [2023/11/23 10:21] (current) pczekalski
Line 1: Line 1:
 ====== Manipulating analogue signals ====== ====== Manipulating analogue signals ======
 +{{:en:iot-open:czapka_b.png?50| General audience classification icon }}{{:en:iot-open:czapka_m.png?50| General audience classification icon }}{{:en:iot-open:czapka_e.png?50| General audience classification icon }}\\
 The analogue inputs and outputs are used when the signal can take a range of values, unlike the digital signal that takes only two values (//HIGH// or //LOW//).  The analogue inputs and outputs are used when the signal can take a range of values, unlike the digital signal that takes only two values (//HIGH// or //LOW//). 
  
Line 47: Line 48:
  
 <code c> <code c>
-#define LED_pin 3              //the pin number is chosen to support PWM generation+#define LED_pin 3          //the pin number is chosen to support PWM generation
  
 void setup() { void setup() {
Line 53: Line 54:
 } }
  
-int value;                     //variable that holds the result of analogue reading+int value;                 //variable that holds the result of analogue reading
  
 void loop() { void loop() {
-  value = analogRead(A0);      //analogRead on Arduino Uno returns the value in the range 0 - 1023 +  value = analogRead(A0);  //analogRead on Arduino Uno returns the value 0-1023 
-  value = value >> 2;          //it should be converted to the value of the range 0 - 255+  value = value >> 2;      //it should be converted to the value 0-255
   analogWrite(LED_pin, value); //writing converted value to PWM output   analogWrite(LED_pin, value); //writing converted value to PWM output
 } }
en/iot-open/introductiontoembeddedprogramming2/cppfundamentals/analog_io.1700605522.txt.gz · Last modified: 2023/11/21 22:25 by pczekalski
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0