{"id":19,"date":"2019-10-09T13:14:50","date_gmt":"2019-10-09T13:14:50","guid":{"rendered":"http:\/\/untanux.lt\/?p=19"},"modified":"2019-10-09T13:18:45","modified_gmt":"2019-10-09T13:18:45","slug":"esp8266-throttle-with-oled-code","status":"publish","type":"post","link":"https:\/\/untanux.lt\/?p=19","title":{"rendered":"ESP8266 throttle with oled code"},"content":{"rendered":"\n<p>#include &lt;Arduino.h><br> #include &lt;U8x8lib.h><\/p>\n\n\n\n<p>#ifdef U8X8_HAVE_HW_SPI<br> #include &lt;SPI.h><br> #endif<\/p>\n\n\n\n<p>U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(\/* reset=*\/ U8X8_PIN_NONE);<\/p>\n\n\n\n<p>const int analogInPin = A0;  \/\/ ESP8266 Analog Pin ADC0 = A0<\/p>\n\n\n\n<p>int sensorValue = 0;  \/\/ value read from the pot<br>\nint outputValue = 0;  \/\/ value to output to a PWM pin<br>\nint analogInput = A0;<br>\nfloat Vout = 0.00;<br>\nfloat Vin = 0.00;<br>\nfloat R1 = 10000.00; \/\/ resistance of R1 (10K) <br>\nfloat R2 = 1000.00; \/\/ resistance of R2 (1K) <br>\nint val = 0;<\/p>\n\n\n\n<p>void setup() {<br>\n  u8x8.begin();<br>\n  \/\/ initialize serial communication at 115200<br>\n  Serial.begin(115200);<br>\n}<\/p>\n\n\n\n<p>void loop() {<br>\n  \/\/ read the analog in value<br>\n  sensorValue = analogRead(analogInPin);<\/p>\n\n\n\n<p>val = analogRead(analogInput);\/\/reads the analog input<br>\n   Vout = (val * 5.00) \/ 1024.00; \/\/ formula for calculating voltage out i.e. V+, here 5.00<br>\n   Vin = Vout \/ (R2\/(R1+R2)); \/\/ formula for calculating voltage in i.e. GND<\/p>\n\n\n\n<p>Serial.print(&#8220;Voltage = &#8220;);<br>\n Serial.println(Vin);<br>\n  float currentValue = Vin;<\/p>\n\n\n\n<p>\/\/ map it to the range of the PWM out<br>\n  \/\/  outputValue = map(sensorValue, 0, 1024, 0, 255);<br>\n  outputValue = map(sensorValue, 279, 868, 0, 255);<br>\n  char buf[20];<br>\n  sprintf(buf, &#8220;In:%d&#8221;, sensorValue);<br>\n  \/\/ print the readings in the Serial Monitor<br>\n  Serial.print(&#8220;sensor = &#8220;);<br>\n  Serial.print(sensorValue);<br>\n  Serial.print(&#8220;\\t output = &#8220;);<br>\n  Serial.println(outputValue);<br>\n  u8x8.setFont(u8x8_font_px437wyse700b_2x2_r);  \/\/ Version 2.25.x<br>\n  u8x8.drawString(0, 0, buf);<br>\n  sprintf(buf, &#8220;Out:%d&#8221;, outputValue);<br>\n  u8x8.drawString(0, 3, buf);<br>\n  u8x8.drawString(0, 6, &#8220;Naujas&#8221;);<br>\n  delay(1000);<br>\n  u8x8.clear();<br>\n  u8x8.drawString(0, 0, &#8220;Voltage:&#8221;);<br>\n  u8x8.drawString(0, 3, &#8220;50.4V&#8221;);<br>\n  delay(1000);<br>\n  u8x8.clear();<br>\n  u8x8.drawString(0, 0, &#8220;Speed:&#8221;);<br>\n  u8x8.drawString(0, 3, &#8220;25km\/h&#8221;);<br>\n  delay(1000);<br>\n  u8x8.clear();<\/p>\n\n\n\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#include &lt;Arduino.h> #include &lt;U8x8lib.h> #ifdef U8X8_HAVE_HW_SPI #include &lt;SPI.h> #endif U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(\/* reset=*\/ U8X8_PIN_NONE); const int analogInPin = A0; \/\/ ESP8266 Analog Pin ADC0 = A0 int sensorValue = 0; \/\/ value read from the pot int outputValue = 0; \/\/ value to output to a PWM pin int analogInput = A0; float Vout = 0.00; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-19","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/untanux.lt\/index.php?rest_route=\/wp\/v2\/posts\/19","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/untanux.lt\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/untanux.lt\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/untanux.lt\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/untanux.lt\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=19"}],"version-history":[{"count":0,"href":"https:\/\/untanux.lt\/index.php?rest_route=\/wp\/v2\/posts\/19\/revisions"}],"wp:attachment":[{"href":"https:\/\/untanux.lt\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/untanux.lt\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/untanux.lt\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}