Giter Site home page Giter Site logo

Comments (4)

hexagon5un avatar hexagon5un commented on July 24, 2024 1

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.

dComposer avatar dComposer commented on July 24, 2024

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.

dComposer avatar dComposer commented on July 24, 2024

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.

dComposer avatar dComposer commented on July 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.