Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 66 lines (49 sloc) 2.335 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#-*- coding: utf-8 -*-
"""


Dojotools - tools for your coding dojo session

Copyright (C) 2009 Flávio Amieiro <amieiro.flavio@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 dated June, 1991.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.

If you find any bugs or have any suggestions email: amieiro.flavio@gmail.com
"""
import sys
import glob

try:
    import firmata
except ImportError:
    sys.stderr.write("""Could not find the firmata module.\nIn order to use the arduino as an output you need to install it.\nGo to https://github.com/lupeke/python-firmata for more information on how to install python-firmata\n""")
    sys.exit(1)

class ArduinoUi(object):
    # we need to add timer functionality to this ui. I'll wait until
    # I fix the gtk dependency, because that will probably change the
    # way we count the time.

    RED_PIN = 7
    GREEN_PIN = 8

    def __init__(self):
        try:
            arduino_path = glob.glob('/dev/ttyUSB*')[0]
        except IndexError:
            sys.stderr.write("""Could not find an arduino device. Looked for /dev/ttyUSB*\nCheck if the arduino is plugged in, and that you have the right permissions.\n""")
            sys.exit(1)

        self.arduino = firmata.Arduino(arduino_path)

        self.arduino.pin_mode(self.GREEN_PIN, firmata.OUTPUT)
        self.arduino.pin_mode(self.RED_PIN, firmata.OUTPUT)

    def show_command_results(self, status, output):
        # we still need to show the output in the terminal
        # window.
        sys.stdout.write(output)

        if status == 0:
            pin_to_light_up = self.GREEN_PIN
            pin_to_dim = self.RED_PIN
        else:
            pin_to_light_up = self.RED_PIN
            pin_to_dim = self.GREEN_PIN

        self.arduino.digital_write(pin_to_light_up, firmata.HIGH)
        self.arduino.digital_write(pin_to_dim, firmata.LOW)
Something went wrong with that request. Please try again.