Skip to content

Commit

Permalink
All python scripts work now under python2 and 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
debiatan committed Dec 18, 2013
1 parent 18f9890 commit cf07f89
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion distance_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
readout = arduino.analogRead(0)
mV = (readout/1024.)*5000
distance = (mV/9.8)*2.54
print readout, mV, 'mV', distance, 'cm'
print(readout, mV, 'mV', distance, 'cm')
time.sleep(0.5)

arduino.close()
6 changes: 3 additions & 3 deletions pyrano.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#You should have received a copy of the GNU General Public License along with
#Cyrano. If not, see <http://www.gnu.org/licenses/>.

import serial, sys, termios
import serial, sys#, termios

INPUT = 0
OUTPUT = 1
Expand Down Expand Up @@ -42,8 +42,8 @@ def __read_word(self):
return ord(self.serial.read())*256 + ord(self.serial.read())

def __write_word(self, value):
self.serial.write(chr(value/256))
self.serial.write(chr(value%256))
self.serial.write(chr(value//256).encode())
self.serial.write(chr(value%256).encode())

def __write_words(self, values):
for value in values:
Expand Down
6 changes: 3 additions & 3 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

time.sleep(2) # Device is reset on incoming connection; wait for cyrano to wake

print 'Pin 13: ', arduino.digitalRead(13) # Read digital
print('Pin 13: ', arduino.digitalRead(13)) # Read digital
arduino.pinMode(13, OUTPUT)
arduino.digitalWrite(13, HIGH) # Write digital
print 'Pin 13: ', arduino.digitalRead(13) # Read digital
print 'Pin 0:', arduino.analogRead(0) # Read analog
print('Pin 13: ', arduino.digitalRead(13)) # Read digital
print('Pin 0:', arduino.analogRead(0)) # Read analog
arduino.analogWrite(9, 100) # PWM output
arduino.close()

0 comments on commit cf07f89

Please sign in to comment.