Comments (4)
Hiya! That's lovely! I'll roll those into the code.
(I haven't been doing as much maintenance on this codebase as I probably should. Thanks for helping out.)
from avr-programming.
I updated Chapter 6's bossButton.py for python 3. The only changes were to add the parenthesis to the print statements and to change the response logic from:
if response = 'X'
to:
if response = b'X'
## Simple demo
## Sits forever listening to serial port
## When you press button, opens website of your choosing.
## Extend this to many buttons and you'll have a physical
## web-launcher.
BOSS_SITE = "http://www.cartalk.com/content/boss-redirect"
## or perhaps more topical...
XKCD = "http://xkcd.com/353/"
## list all serial ports being used: python -m serial.tools.list_ports
SERIAL_PORT = "/dev/cu.usbserial-14130"
BAUD_RATE = 9600
import serial
import webbrowser
sp = serial.Serial(SERIAL_PORT, BAUD_RATE, timeout = 5)
sp.flush()
print("Boss Button")
while(1): # Sit and wait forever
response = sp.read(1) # get one byte
if response == b'O':
print("Got OK Byte. Waiting for button press.")
elif response == b'X':
print("Got Boss Byte! Alarm!")
webbrowser.open(BOSS_SITE)
else:
print("Got nothing. Still waiting.")
from avr-programming.
Chapter 7's serialScope.py updated for python 3:
import serial
def readValue(serialPort):
return(ord(serialPort.read(1)))
def plotValue(value):
""" Displays the value on a scaled scrolling bargraph"""
leadingSpaces = "-" * int(value*(SCREEN_WIDTH-3) / 255)
print(f"{leadingSpaces} {value:03}")
def cheapoScope(serialPort):
while(1):
newValue = readValue(serialPort)
plotValue(newValue)
if __name__ == "__main__":
## list all serial ports being used: python -m serial.tools.list_ports
PORT = '/dev/cu.usbserial-14230' # update to whatever port is listed in serial.tools.list_ports
BAUDRATE = 9600
TIMEOUT = None
SCREEN_WIDTH = 80
## Take command-line arguments to override defaults above
import sys
if len(sys.argv) == 3:
port = sys.argv[1]
baudrate = int(sys.argv[2])
else: # nothing passed, use defaults
print ("Optional arguments port, baudrate set to defaults.")
port, baudrate = (PORT, BAUDRATE)
serialPort = serial.Serial(port, baudrate, timeout=TIMEOUT)
serialPort.flush()
cheapoScope(serialPort)
from avr-programming.
My pleasure! As I convert more python code over I'll post them into this issue. Thanks for writing this great book!
from avr-programming.
Related Issues (20)
- pwmOnAnyPin: Incorrect register bit access
- Chapter 8 Interrupt code and serialScope do not match together
- Unclear statement Chapter 10: only 3 LEDs for hardware PWM when ATmega168PA has 6 HOT 1
- issue building makefile on ubuntu HOT 4
- Windows 10. avr-gcc and avrdude want different MCU strings
- USART.c ATmega16A fix.
- file not found error on first make attempt HOT 3
- When changing Makefile new hex is not generated
- question about makefile
- download zip fails with a 0kb download
- Lost the ability to receive bytes via USART by Chapter 9! HOT 1
- Issue with Serial Connection on Arduino HOT 2
- littlehacks.org - looks like it's down HOT 2
- compiler warnings atmel328p HOT 1
- avr 328p, crystal and leds HOT 1
- Magical number 3000 in servoWorkout.c (chapter 11)
- magical number 3000 in servoWorkout.c (chapter 11)
- examples 11-1 vs 11-2, prescaling and count speed HOT 1
- Some thoughts
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from avr-programming.