Description

The device takes sound as an input and outputs light based on how loud the sound is. On one end is a microphone, which is the input. Based on how loud the sound picked up by the microphone is, a servo will turn a potentiometer a certain amount. Based on the position of the potentiometer, the LED will light up brighter or dimmer. In the end, louder sounds will lead to more light, while quieter sounds will lead to less light.

Demonstration:

Progress Videos

The progress videos of the input and output domains.

The overall layout of the project

Input Sound detector to detect the volume of the sound produced.

“Servometer” (servo coupled to  potentiometer)  controlled by the input from the sound volume. It rotates the potentiometer.

LED output to produce different variation of brightness as controlled by the input from potentiometer

Discussion

We’ll start with what was easy. Getting the input, output, and middle man wired up was probably the easiest part. The code wasn’t too difficult, but there was some tweaking needed in order to get the desired behavior (mostly tweaking the ranges).

One of the big challenges was actually assembling the middle man portion of the device; namely, coupling the servo motor to the potentiometer. At first, I tried just taping a horn to the potentiometer shaft, but that wasn’t reliable enough, and looked terrible. In the end, I 3D printed a shaft coupler made for an SG-90 hobby servo (what we used) and drilled a hole in the other end of it to friction-fit onto the potentiometer. That did the job.

Schematic

Code

  1. <span class="com">/*
  2. Project 1
  3. Seth Geiser (sgeiser) and Olaitan Adisa (okadisa)
  4. Collaboration: Ola is my partner and she came up with the
  5. schematic and other ideas.
  6. Some references:
  7. </span><iframe title="Arduino - Use Potentiometer To Control LED Brightness" width="620" height="349" src="https://www.youtube.com/embed/RBYVUTIU4FE?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" data-origwidth="620" data-origheight="349" style="width: 1264px; height: 711.51px;"></iframe><span class="com">
  8. https://courses.ideate.cmu.edu/60-223/s2020/tutorials/I2C-lcd
  9. https://courses.ideate.cmu.edu/60-223/s2020/reference/class-log#codebook-periodic-updating
  10. Challenge: The biggest challenge was coupling the servo to
  11. the potentiometer so that we could adjust the LED brightness.
  12. Next time: I don't know... keep going?
  13. Description: The purpose is to create a double-transducer. The
  14. input is sound, read by a sound detector. The sound reading
  15. triggers a servo (coupled to a potentiometer) to change its
  16. position, thus changing the potentiometer's position. This
  17. changes the brightness of the LED. Louder sounds should result
  18. in the LED emitting brighter light, and vice versa.
  19. Pin mapping:
  20. pin | mode | description
  21. -----|-------|------------
  22. A0 input potentiometer
  23. A1 input sound detector
  24. 11 output LED
  25. 2 output servo
  26. SDA/SCL display
  27. */</span><span class="pln">
  28. </span><span class="com">#include</span><span class="pln"> </span><span class="str"><Wire.h></span><span class="pln">
  29. </span><span class="com">#include</span><span class="pln"> </span><span class="str"><LiquidCrystal_I2C.h></span><span class="pln">
  30. </span><span class="com">#include</span><span class="pln"> </span><span class="str"><Servo.h></span><span class="pln">
  31. </span><span class="typ">Servo</span><span class="pln"> myservo</span><span class="pun">;</span><span class="pln">
  32. </span><span class="com">/*
  33. Create an LCD display object called "screen" with I2C address 0x27
  34. which is 16 columns wide and 2 rows tall.
  35. */</span><span class="pln">
  36. </span><span class="typ">LiquidCrystal_I2C</span><span class="pln"> screen</span><span class="pun">(</span><span class="lit">0x27</span><span class="pun">,</span><span class="pln"> </span><span class="lit">16</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">);</span><span class="pln">
  37. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> POTPIN </span><span class="pun">=</span><span class="pln"> A0</span><span class="pun">;</span><span class="pln">
  38. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> SOUNDPIN </span><span class="pun">=</span><span class="pln"> A1</span><span class="pun">;</span><span class="pln">
  39. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> LEDPIN </span><span class="pun">=</span><span class="pln"> </span><span class="lit">11</span><span class="pun">;</span><span class="pln">
  40. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> SERVOPIN </span><span class="pun">=</span><span class="pln"> </span><span class="lit">2</span><span class="pun">;</span><span class="pln">
  41. </span><span class="com">// "global" variables in this section can be used by any function in the whole sketch</span><span class="pln">
  42. </span><span class="kwd">float</span><span class="pln"> filtered_val </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln"> </span><span class="com">// this variable, of type float (decimal), holds the filtered sensor value</span><span class="pln">
  43. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">float</span><span class="pln"> PREV_WEIGHT </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0.99</span><span class="pun">;</span><span class="pln"> </span><span class="com">// this variable, of type float (decimal), determines the previously filtered value's weight.</span><span class="pln">
  44. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">float</span><span class="pln"> CUR_WEIGHT </span><span class="pun">=</span><span class="pln"> </span><span class="lit">1</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> PREV_WEIGHT</span><span class="pun">;</span><span class="pln"> </span><span class="com">// this variable, of type float (decimal), determines the current sample's weight.</span><span class="pln">
  45. </span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> timer </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln"> </span><span class="com">// variable for timing</span><span class="pln">
  46. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> INTERVAL </span><span class="pun">=</span><span class="pln"> </span><span class="lit">250</span><span class="pun">;</span><span class="pln"> </span><span class="com">// milliseconds between updates</span><span class="pln">
  47. </span><span class="kwd">void</span><span class="pln"> setup</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  48. pinMode</span><span class="pun">(</span><span class="pln">POTPIN</span><span class="pun">,</span><span class="pln"> INPUT</span><span class="pun">);</span><span class="pln">
  49. pinMode</span><span class="pun">(</span><span class="pln">SOUNDPIN</span><span class="pun">,</span><span class="pln"> INPUT</span><span class="pun">);</span><span class="pln">
  50. pinMode</span><span class="pun">(</span><span class="pln">LEDPIN</span><span class="pun">,</span><span class="pln"> OUTPUT</span><span class="pun">);</span><span class="pln">
  51. myservo</span><span class="pun">.</span><span class="pln">attach</span><span class="pun">(</span><span class="pln">SERVOPIN</span><span class="pun">);</span><span class="pln">
  52. screen</span><span class="pun">.</span><span class="pln">init</span><span class="pun">();</span><span class="pln">
  53. screen</span><span class="pun">.</span><span class="pln">backlight</span><span class="pun">();</span><span class="pln">
  54. screen</span><span class="pun">.</span><span class="pln">home</span><span class="pun">();</span><span class="pln">
  55. filtered_val </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">SOUNDPIN</span><span class="pun">);</span><span class="pln">
  56. </span><span class="pun">}</span><span class="pln">
  57. </span><span class="kwd">void</span><span class="pln"> loop</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  58. </span><span class="kwd">int</span><span class="pln"> soundValue </span><span class="pun">=</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">float</span><span class="pun">)</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">SOUNDPIN</span><span class="pun">);</span><span class="pln"> </span><span class="com">// casting from int to float</span><span class="pln">
  59. </span><span class="kwd">int</span><span class="pln"> soundValueLCD </span><span class="pun">=</span><span class="pln"> map</span><span class="pun">(</span><span class="pln">soundValue</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">500</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">99</span><span class="pun">);</span><span class="pln"> </span><span class="com">// mapping first input (sound)to range 0-99</span><span class="pln">
  60. filtered_val </span><span class="pun">=</span><span class="pln"> filtered_val </span><span class="pun">*</span><span class="pln"> PREV_WEIGHT </span><span class="pun">+</span><span class="pln"> soundValue </span><span class="pun">*</span><span class="pln"> CUR_WEIGHT</span><span class="pun">;</span><span class="pln">
  61. </span><span class="kwd">int</span><span class="pln"> servoPosition </span><span class="pun">=</span><span class="pln"> map</span><span class="pun">(</span><span class="pln">filtered_val</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">400</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">180</span><span class="pun">);</span><span class="pln"> </span><span class="com">// mapping sound values to range 0 - 180 degrees</span><span class="pln">
  62. </span><span class="kwd">int</span><span class="pln"> servoValueLCD </span><span class="pun">=</span><span class="pln"> map</span><span class="pun">(</span><span class="pln">servoPosition</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">180</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">99</span><span class="pun">);</span><span class="pln"> </span><span class="com">// mapping first output (servo)to 0-99</span><span class="pln">
  63. myservo</span><span class="pun">.</span><span class="pln">write</span><span class="pun">(</span><span class="pln">servoPosition</span><span class="pun">);</span><span class="pln">
  64. </span><span class="kwd">int</span><span class="pln"> potVal </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">POTPIN</span><span class="pun">);</span><span class="pln">
  65. </span><span class="kwd">int</span><span class="pln"> potValueLCD </span><span class="pun">=</span><span class="pln"> map</span><span class="pun">(</span><span class="pln">potVal</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1024</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">99</span><span class="pun">);</span><span class="pln">
  66. </span><span class="kwd">int</span><span class="pln"> mapPotVal </span><span class="pun">=</span><span class="pln"> map</span><span class="pun">(</span><span class="pln">potVal</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1024</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">254</span><span class="pun">);</span><span class="pln"> </span><span class="com">// pot to LED values</span><span class="pln">
  67. analogWrite</span><span class="pun">(</span><span class="pln">LEDPIN</span><span class="pun">,</span><span class="pln"> mapPotVal</span><span class="pun">);</span><span class="pln">
  68. </span><span class="kwd">int</span><span class="pln"> ledValueLCD </span><span class="pun">=</span><span class="pln"> map</span><span class="pun">(</span><span class="pln">mapPotVal</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">254</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">99</span><span class="pun">);</span><span class="pln">
  69. </span><span class="com">// updating the LCD output</span><span class="pln">
  70. </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">millis</span><span class="pun">()</span><span class="pln"> </span><span class="pun">>=</span><span class="pln"> timer</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  71. screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  72. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">((</span><span class="typ">String</span><span class="pun">)</span><span class="pln"> </span><span class="str">"i:"</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> soundValueLCD</span><span class="pun">);</span><span class="pln">
  73. screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">6</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  74. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">((</span><span class="typ">String</span><span class="pun">)</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> </span><span class="str">"m:"</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> servoValueLCD</span><span class="pun">);</span><span class="pln">
  75. screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">8</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">);</span><span class="pln">
  76. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">((</span><span class="typ">String</span><span class="pun">)</span><span class="pln"> potValueLCD </span><span class="pun">);</span><span class="pln">
  77. screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">12</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">);</span><span class="pln">
  78. screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">((</span><span class="typ">String</span><span class="pun">)</span><span class="pln"> </span><span class="str">"o:"</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> ledValueLCD</span><span class="pun">);</span><span class="pln">
  79. timer </span><span class="pun">=</span><span class="pln"> millis</span><span class="pun">()</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> INTERVAL</span><span class="pun">;</span><span class="pln"> </span><span class="com">// and update timer</span><span class="pln">
  80. </span><span class="pun">}</span><span class="pln">
  81. </span><span class="pun">}</span>
<span class="com">/*
   Project 1
   Seth Geiser (sgeiser) and Olaitan Adisa (okadisa)

   Collaboration: Ola is my partner and she came up with the
   schematic and other ideas.
   Some references:
   </span><iframe title="Arduino - Use Potentiometer To Control LED Brightness" width="620" height="349" src="https://www.youtube.com/embed/RBYVUTIU4FE?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" data-origwidth="620" data-origheight="349" style="width: 1264px; height: 711.51px;"></iframe><span class="com">
   https://courses.ideate.cmu.edu/60-223/s2020/tutorials/I2C-lcd
   https://courses.ideate.cmu.edu/60-223/s2020/reference/class-log#codebook-periodic-updating

   Challenge: The biggest challenge was coupling the servo to
   the potentiometer so that we could adjust the LED brightness.

   Next time: I don't know... keep going?

   Description: The purpose is to create a double-transducer. The
   input is sound, read by a sound detector. The sound reading
   triggers a servo (coupled to a potentiometer) to change its
   position, thus changing the potentiometer's position. This
   changes the brightness of the LED. Louder sounds should result
   in the LED emitting brighter light, and vice versa.

   Pin mapping:

   pin  | mode  | description
   -----|-------|------------
   A0     input   potentiometer
   A1     input   sound detector
   11     output  LED
   2      output  servo
   SDA/SCL        display

*/</span><span class="pln">

</span><span class="com">#include</span><span class="pln"> </span><span class="str"><Wire.h></span><span class="pln">
</span><span class="com">#include</span><span class="pln"> </span><span class="str"><LiquidCrystal_I2C.h></span><span class="pln">
</span><span class="com">#include</span><span class="pln"> </span><span class="str"><Servo.h></span><span class="pln">
</span><span class="typ">Servo</span><span class="pln"> myservo</span><span class="pun">;</span><span class="pln">

</span><span class="com">/*
   Create an LCD display object called "screen" with I2C address 0x27
   which is 16 columns wide and 2 rows tall.
*/</span><span class="pln">

</span><span class="typ">LiquidCrystal_I2C</span><span class="pln"> screen</span><span class="pun">(</span><span class="lit">0x27</span><span class="pun">,</span><span class="pln"> </span><span class="lit">16</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">);</span><span class="pln">

</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> POTPIN </span><span class="pun">=</span><span class="pln"> A0</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> SOUNDPIN </span><span class="pun">=</span><span class="pln"> A1</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> LEDPIN </span><span class="pun">=</span><span class="pln"> </span><span class="lit">11</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> SERVOPIN </span><span class="pun">=</span><span class="pln"> </span><span class="lit">2</span><span class="pun">;</span><span class="pln">

</span><span class="com">// "global" variables in this section can be used by any function in the whole sketch</span><span class="pln">
</span><span class="kwd">float</span><span class="pln"> filtered_val </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">  </span><span class="com">// this variable, of type float (decimal), holds the filtered sensor value</span><span class="pln">
</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">float</span><span class="pln"> PREV_WEIGHT </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0.99</span><span class="pun">;</span><span class="pln"> </span><span class="com">// this variable, of type float (decimal), determines the previously filtered value's weight.</span><span class="pln">
</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">float</span><span class="pln"> CUR_WEIGHT </span><span class="pun">=</span><span class="pln"> </span><span class="lit">1</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> PREV_WEIGHT</span><span class="pun">;</span><span class="pln"> </span><span class="com">// this variable, of type float (decimal), determines the current sample's weight.</span><span class="pln">

</span><span class="kwd">unsigned</span><span class="pln"> </span><span class="kwd">long</span><span class="pln"> timer </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln"> </span><span class="com">// variable for timing</span><span class="pln">
</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> INTERVAL </span><span class="pun">=</span><span class="pln"> </span><span class="lit">250</span><span class="pun">;</span><span class="pln"> </span><span class="com">// milliseconds between updates</span><span class="pln">


</span><span class="kwd">void</span><span class="pln"> setup</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  pinMode</span><span class="pun">(</span><span class="pln">POTPIN</span><span class="pun">,</span><span class="pln"> INPUT</span><span class="pun">);</span><span class="pln">
  pinMode</span><span class="pun">(</span><span class="pln">SOUNDPIN</span><span class="pun">,</span><span class="pln"> INPUT</span><span class="pun">);</span><span class="pln">
  pinMode</span><span class="pun">(</span><span class="pln">LEDPIN</span><span class="pun">,</span><span class="pln"> OUTPUT</span><span class="pun">);</span><span class="pln">

  myservo</span><span class="pun">.</span><span class="pln">attach</span><span class="pun">(</span><span class="pln">SERVOPIN</span><span class="pun">);</span><span class="pln">
  screen</span><span class="pun">.</span><span class="pln">init</span><span class="pun">();</span><span class="pln">
  screen</span><span class="pun">.</span><span class="pln">backlight</span><span class="pun">();</span><span class="pln">
  screen</span><span class="pun">.</span><span class="pln">home</span><span class="pun">();</span><span class="pln">

  filtered_val </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">SOUNDPIN</span><span class="pun">);</span><span class="pln">

</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">void</span><span class="pln"> loop</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">

  </span><span class="kwd">int</span><span class="pln"> soundValue </span><span class="pun">=</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">float</span><span class="pun">)</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">SOUNDPIN</span><span class="pun">);</span><span class="pln"> </span><span class="com">// casting from int to float</span><span class="pln">

  </span><span class="kwd">int</span><span class="pln"> soundValueLCD </span><span class="pun">=</span><span class="pln"> map</span><span class="pun">(</span><span class="pln">soundValue</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">500</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">99</span><span class="pun">);</span><span class="pln">  </span><span class="com">// mapping first input (sound)to range 0-99</span><span class="pln">

  filtered_val </span><span class="pun">=</span><span class="pln"> filtered_val </span><span class="pun">*</span><span class="pln"> PREV_WEIGHT </span><span class="pun">+</span><span class="pln"> soundValue </span><span class="pun">*</span><span class="pln"> CUR_WEIGHT</span><span class="pun">;</span><span class="pln">

  </span><span class="kwd">int</span><span class="pln"> servoPosition </span><span class="pun">=</span><span class="pln"> map</span><span class="pun">(</span><span class="pln">filtered_val</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">400</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">180</span><span class="pun">);</span><span class="pln"> </span><span class="com">// mapping sound values to range 0 - 180 degrees</span><span class="pln">

  </span><span class="kwd">int</span><span class="pln"> servoValueLCD </span><span class="pun">=</span><span class="pln"> map</span><span class="pun">(</span><span class="pln">servoPosition</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">180</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">99</span><span class="pun">);</span><span class="pln"> </span><span class="com">// mapping first output (servo)to 0-99</span><span class="pln">

  myservo</span><span class="pun">.</span><span class="pln">write</span><span class="pun">(</span><span class="pln">servoPosition</span><span class="pun">);</span><span class="pln">

  </span><span class="kwd">int</span><span class="pln"> potVal </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">POTPIN</span><span class="pun">);</span><span class="pln">
  </span><span class="kwd">int</span><span class="pln"> potValueLCD </span><span class="pun">=</span><span class="pln"> map</span><span class="pun">(</span><span class="pln">potVal</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1024</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">99</span><span class="pun">);</span><span class="pln">

  </span><span class="kwd">int</span><span class="pln"> mapPotVal </span><span class="pun">=</span><span class="pln"> map</span><span class="pun">(</span><span class="pln">potVal</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1024</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">254</span><span class="pun">);</span><span class="pln">   </span><span class="com">// pot to LED values</span><span class="pln">

  analogWrite</span><span class="pun">(</span><span class="pln">LEDPIN</span><span class="pun">,</span><span class="pln"> mapPotVal</span><span class="pun">);</span><span class="pln">
  </span><span class="kwd">int</span><span class="pln"> ledValueLCD </span><span class="pun">=</span><span class="pln"> map</span><span class="pun">(</span><span class="pln">mapPotVal</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">254</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">99</span><span class="pun">);</span><span class="pln">


  </span><span class="com">// updating the LCD output</span><span class="pln">
  </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">millis</span><span class="pun">()</span><span class="pln"> </span><span class="pun">>=</span><span class="pln"> timer</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">);</span><span class="pln">
    screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">((</span><span class="typ">String</span><span class="pun">)</span><span class="pln"> </span><span class="str">"i:"</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> soundValueLCD</span><span class="pun">);</span><span class="pln">
    screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">6</span><span class="pun">,</span><span class="pln"> </span><span class="lit">0</span><span class="pun">);</span><span class="pln">
    screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">((</span><span class="typ">String</span><span class="pun">)</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> </span><span class="str">"m:"</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> servoValueLCD</span><span class="pun">);</span><span class="pln">
    screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">8</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">);</span><span class="pln">
    screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">((</span><span class="typ">String</span><span class="pun">)</span><span class="pln"> potValueLCD </span><span class="pun">);</span><span class="pln">
    screen</span><span class="pun">.</span><span class="pln">setCursor</span><span class="pun">(</span><span class="lit">12</span><span class="pun">,</span><span class="pln"> </span><span class="lit">1</span><span class="pun">);</span><span class="pln">
    screen</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">((</span><span class="typ">String</span><span class="pun">)</span><span class="pln"> </span><span class="str">"o:"</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> ledValueLCD</span><span class="pun">);</span><span class="pln">
    timer </span><span class="pun">=</span><span class="pln"> millis</span><span class="pun">()</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> INTERVAL</span><span class="pun">;</span><span class="pln"> </span><span class="com">// and update timer</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">

</span><span class="pun">}</span>