示例#1
0
文件: ADC2.py 项目: tpaulus/DCC-13
#! /usr/bin/python
#Written By Tom Paulus, @tompaulus, www.tompaulus.com
#For DCC 2013.1

import time
import spidev
import RPi.GPIO as GPIO
from Adafruit_LEDBackpack.Adafruit_7Segment import SevenSegment
import smbus

GPIO.setmode(GPIO.BCM)
segment = SevenSegment(address=0x70)  # which port the display is
spi = spidev.SpiDev()
light_adc = 7
l = list()
statusLED = 25
print "Press CTRL+Z to exit"
GPIO.setup(statusLED, GPIO.OUT)


def analogRead(port):
    """Read the given ADC port and preform the necessary shifting of bits"""
    spi.open(0, 0)
    if (port > 7) or (port < 0):
        print 'analogRead -- Port Error, Must use a port between 0 and 7'
        return -1
    r = spi.xfer2([1, (8 + port) << 4, 0])
    value = ((r[1] & 3) << 8) + r[2]
    spi.close()
    return value
示例#2
0
from Adafruit_LEDBackpack.Adafruit_7Segment import SevenSegment
from Ard import *

green = 25
yellow = 24
red = 23
mosfet = 18
led1 = 4
led2 = 22
led3 = 21
pot_adc = 7
light_adc = 6

mode = 0
l = list()
segment = SevenSegment(address=0x70) #which port the display is
A = Arduino("BCM") #define the port name style
print "Press CTRL+Z to exit"
#Set the port types
A.pinMode(green,'IN')
A.pinMode(yellow,'IN')
A.pinMode(red,'IN')
A.pinMode(led1,'OUT')
A.pinMode(led2,'OUT')
A.pinMode(led3,'OUT')

#Turn off all LEDs
A.digitalWrite(led1,"LOW")
A.digitalWrite(led2,"LOW")
A.digitalWrite(led3,"LOW")
示例#3
0
#!/usr/bin/python

import time
import datetime
from Adafruit_LEDBackpack.Adafruit_7Segment import SevenSegment

# ===========================================================================
# Clock Example
# ===========================================================================
segment = SevenSegment(address=0x74)

print "Press CTRL+Z to exit"

c = 0
# Continually update the time on a 4 char, 7-segment display
# Continually update the 8x8 display one pixel at a time


# Set hours
segment.writeDigitRaw(0, 0x00)   
segment.writeDigitRaw(1, 0x01)          # Ones
# Set minutes
segment.writeDigitRaw(3, 0x02)   # Tens
segment.writeDigitRaw(4, 0x03)        # Ones
# Toggle color
segment.setColon(1)              # Toggle colon at 1Hz

示例#4
0
#!/usr/bin/python

import time
import datetime
from Adafruit_LEDBackpack.Adafruit_7Segment import SevenSegment
from Adafruit_LEDBackpack.Adafruit_8x8 import EightByEight

# ===========================================================================
# 8x8 Pixel Example
# ===========================================================================
grid = EightByEight(address=0x70)

# ===========================================================================
# Clock Example
# ===========================================================================
segment = SevenSegment(address=0x74)

print "Press CTRL+Z to exit"

c = 0
# Continually update the time on a 4 char, 7-segment display
# Continually update the 8x8 display one pixel at a time
while(True):
  now = datetime.datetime.now()
  hour = now.hour
  minute = now.minute
  second = now.second
 
  # Set hours
  segment.writeDigit(0, int(hour / 10))     # Tens
  segment.writeDigit(1, hour % 10)          # Ones