Skip to content

Commit

Permalink
Fixes analogWrite to work properly
Browse files Browse the repository at this point in the history
Analog write was not working for a wide range of hex values.  This short fix remedies this.
  • Loading branch information
hungyao committed Feb 9, 2012
1 parent 8ba9762 commit 96d181e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions arduino/arduino.py
Expand Up @@ -38,12 +38,17 @@ def getState(self, pin):

def analogWrite(self, pin, value):
self.__sendData('3')
self.__sendPin(pin)
hex_value = hex(value)[2:]
if(len(hex_value)==1):
self.__sendData('0')
hex1 = '0'
hex2 = hex_value[0]
else:
self.__sendData(hex_value[0])
self.__sendData(hex_value[1])
hex1 = hex_value[0]
hex2 = hex_value[1]

self.__sendData(hex1)
self.__sendData(hex2)
return True

def analogRead(self, pin):
Expand Down

0 comments on commit 96d181e

Please sign in to comment.