def write_temp_to_7segment (temp):
  segment = SevenSegment(address=0x71)
  hundreds = int (temp / 100)
  if (hundreds > 0):
      segment.writeDigit(1, hundreds)            # Hundreds 
  temp = temp - (hundreds * 100)
  segment.writeDigit(3, int(temp / 10))      # tens
  segment.writeDigit(4, int(temp % 10))      # ones 
Exemplo n.º 2
0
class ClockThread(threading.Thread):

   def __init__(self):
      threading.Thread.__init__(self)
      self.segment = SevenSegment(address=0x70)
      self.stopping=False

   def stop(self):
      self.segment.disp.clear()
      self.stopping=True

   def run(self):
      while(not self.stopping):
          now = datetime.datetime.now(pytz.timezone('America/Los_Angeles'))
          hour = now.hour

          minute = now.minute
          second = now.second

          # Set hours
          self.segment.writeDigit(0, int(hour / 10))     # Tens
          self.segment.writeDigit(1, hour % 10)          # Ones
          # Set minutes
          self.segment.writeDigit(3, int(minute / 10))   # Tens
          self.segment.writeDigit(4, minute % 10)        # Ones

          time.sleep(1)
Exemplo n.º 3
0
class ClockThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.segment = SevenSegment(address=0x70)
        self.stopping = False

    def stop(self):
        self.segment.disp.clear()
        self.stopping = True

    def run(self):
        while (not self.stopping):
            now = datetime.datetime.now(pytz.timezone('Europe/London'))
            hour = now.hour

            minute = now.minute
            second = now.second

            # Set hours
            self.segment.writeDigit(0, int(hour / 10))  # Tens
            self.segment.writeDigit(1, hour % 10)  # Ones
            # Set minutes
            self.segment.writeDigit(3, int(minute / 10))  # Tens
            self.segment.writeDigit(4, minute % 10)  # Ones

            time.sleep(1)
Exemplo n.º 4
0
class ClockThread(threading.Thread):
    def __init__(self, settings):
        threading.Thread.__init__(self)
        self.segment = SevenSegment(address=0x70)
        self.stopping = False
        # self.settings = Settings.Settings()
        self.settings = settings
        self.colon = 0

    def stop(self):
        self.segment.disp.clear()
        self.stopping = True

    def run(self):
        while (not self.stopping):
            now = datetime.datetime.now(pytz.timezone(self.settings.get('timezone')))
            # hour = now.hour
            hour = int(now.strftime("%I").lstrip("0"))

            minute = now.minute
            second = now.second

            # Set hours
            self.segment.writeDigit(0, int(hour / 10))  # Tens
            self.segment.writeDigit(1, hour % 10)  # Ones
            # Set minutes
            self.segment.writeDigit(3, int(minute / 10))  # Tens
            self.segment.writeDigit(4, minute % 10)  # Ones
            # Toggle colon
            self.segment.writeDigitRaw(2, self.colon)
            self.colon = self.colon ^ 0x2

            time.sleep(1)
Exemplo n.º 5
0
class ClockThread(threading.Thread):
    def __init__(self, settings):
        threading.Thread.__init__(self)
        self.segment = SevenSegment(address=0x70)
        self.stopping = False
        # self.settings = Settings.Settings()
        self.settings = settings
        self.colon = 0

    def stop(self):
        self.segment.disp.clear()
        self.stopping = True

    def run(self):
        while (not self.stopping):
            now = datetime.datetime.now(
                pytz.timezone(self.settings.get('timezone')))
            # hour = now.hour
            hour = int(now.strftime("%I").lstrip("0"))

            minute = now.minute
            second = now.second

            # Set hours
            self.segment.writeDigit(0, int(hour / 10))  # Tens
            self.segment.writeDigit(1, hour % 10)  # Ones
            # Set minutes
            self.segment.writeDigit(3, int(minute / 10))  # Tens
            self.segment.writeDigit(4, minute % 10)  # Ones
            # Toggle colon
            self.segment.writeDigitRaw(2, self.colon)
            self.colon = self.colon ^ 0x2

            time.sleep(1)
Exemplo n.º 6
0
class ClockThread (threading.Thread):
	
	def __init__(self):
		threading.Thread.__init__(self)
		self._segment = SevenSegment(address=0x70)
		self._segment.disp.clear()
		self.ended = False
		
	@property
	def segment(self):
		return self._segment
		
	@property
	def hour(self):
		return self._hour
		
	@property
	def minute(self):
		return self._minute
	
	def end(self):
		self._segment.disp.clear()
		self.ended = True
	
	def run(self):
		while(self.ended != True):
			now = datetime.datetime.now()
			hour = now.hour
			minute = now.minute
			second = now.second
			
			self._hour = hour
			self._minute = minute
			
			hourTensPlace = int(hour / 10)
			hourOnesPlace = hour % 10
			minuteTensPlace = int(minute / 10)
			minuteOnesPlace = minute % 10
			
			self._segment.writeDigit(0, hourTensPlace)
			self._segment.writeDigit(1, hourOnesPlace)
			self._segment.writeDigit(3, minuteTensPlace)
			self._segment.writeDigit(4, minuteOnesPlace)
		self._segment.disp.clear()
		logger.info('Clock is powering down')
Exemplo n.º 7
0
import Adafruit_BBIO.ADC as ADC
import time
import datetime
from Adafruit_7Segment import SevenSegment

segment = SevenSegment(address=0x70)
sensor_pin = "P9_40"

ADC.setup()

while True:
    reading = ADC.read(sensor_pin)
    millivolts = reading * 1800
    temp_c = (millivolts - 500) / 10

    segment.writeDigit(0, int(temp_c / 10))
    segment.writeDigit(1, int(temp_c % 10))
    segment.writeDigit(3, 12)

    segment.setColon(1)
    time.sleep(1)
#!/usr/bin/python

from Adafruit_7Segment import SevenSegment
import RPi.GPIO as io

#io.setmode(io.BCM)
segment = SevenSegment(address=0x70)

while True:
	position = raw_input('Position: ')
	if position == 'end': break
	elif position == 'clear':
		position = raw_input('Position: ')
		if position == 'all': segment.clear()
		else: segment.clear(int(position))
	else:
		number = raw_input('Number: ')
		'if len(number) == 1:'
		segment.writeDigit(int(position) , int(number))
		'else: print ''Must be digit'
	print segment.getBuffer()
segment.clear()
Exemplo n.º 9
0
#    1 1   3    2    1    0
#    0 1   2    3    1    0

from Adafruit_7Segment import SevenSegment
import gaugette.rotary_encoder
import gaugette.switch
import math

segment = SevenSegment(address=0x70)
segment.disp.setBufferRow(0, 0);
segment.disp.setBufferRow(1, 0);
segment.disp.setBufferRow(2, 0);
segment.disp.setBufferRow(3, 0);
segment.disp.setBufferRow(4, 0);

segment.writeDigit(0, 1);
segment.writeDigit(1, 2);
#segment.writeDigit(2, 0);
segment.writeDigit(3, 3);
segment.writeDigit(4, 4);

if gaugette.platform == 'raspberrypi':
    A_PIN  = 7
    B_PIN  = 9
    SW_PIN = 8
else: # beaglbone
    A_PIN  = "P9_13"
    B_PIN  = "P9_15"
    SW_PIN = "P9_11"

encoder = gaugette.rotary_encoder.RotaryEncoder(B_PIN, A_PIN)
Exemplo n.º 10
0
    millivolts = read_adc4 * ( 3300.0 / 1024.0)

    # 10 mv per degree
    temp_C = ((millivolts - 100.0) / 10.0) - 40.0

    # convert celsius to fahrenheit
    temp_F = ( temp_C * 9.0 / 5.0 ) + 32

    # remove decimal point from millivolts
    millivolts = "%d" % millivolts

    # show only one decimal place for temprature and voltage readings
    print_temp = int(temp_C*10)
    temp_C = "%.1f" % temp_C
    temp_F = "%.1f" % temp_F


    if DEBUG:
        print "read_adc4:\t", read_adc4
        print "millivolts:\t", millivolts
        print "temp_C:\t\t", temp_C
        print "temp_F:\t\t", temp_F
        print

    segment.writeDigit(0, (print_temp%10000)/1000)
    segment.writeDigit(1, (print_temp%1000)/100)
    segment.writeDigit(3, (print_temp%100)/10,True)
    segment.writeDigit(4, print_temp%10)
    time.sleep(.25)
    GPIO.output(25,False)
    time.sleep(.75)
Exemplo n.º 11
0
sensor = MAX31855(CLK, CS, DO)


# ===========================================================================
# Clock Example
# ===========================================================================

# Loop printing measurements every second.
while True:
  temp = sensor.readTempC()
  internal = sensor.readInternalC()

  #print 'Thermocouple: {0:0.3F}*C'.format(temp, c_to_f(temp))
  #print 'Internal: {0:0.3F}*C'.format(internal, c_to_f(internal))

  if (temp >= 100):
    segment.writeDigit(0, int(temp / 100))
  else:
    backpack.setBufferRow(0, 0)

  segment.writeDigit(1, int(temp / 10))
  segment.writeDigit(3, int(temp) % 10)
  segment.writeDigit(4, 0xC)

  # set deg
  #backpack.setBufferRow(5,1)
  segment.writeDigit(2, 0xf)

  time.sleep(1.0)

Exemplo n.º 12
0
# Scalextric Timer
# Reports on the time lapsed between detections on the reed sensor
# Also flashes an LED on each lap detection, and green to indicate fastest lap
# 2 Buttons - one to reset timings, one to display fastest lap
# Uses adafruit library to display lap times on 7 segment, 4 digit display

# Import libraries
import RPi.GPIO as GPIO
import time
from Adafruit_7Segment import SevenSegment

# Set i2c address for display, and display zeros
segment = SevenSegment(address=0x70)
segment.writeDigit(0, 0)
segment.writeDigit(1, 0)
segment.writeDigit(3, 0)
segment.writeDigit(4, 0)

# Configure the Pi to use the BCM pin names
GPIO.setmode(GPIO.BCM)

# pins used for the switches, reed sensor and LED
reset = 18
fastest_lap = 23
reed = 24
red_led = 17
green_led = 27

# configure outputs for LED
GPIO.setup(red_led, GPIO.OUT)
GPIO.setup(green_led, GPIO.OUT)
Exemplo n.º 13
0
		segment.writeDigitRaw(0, 0x08)		# underscore means no busses but I'm still working
		segment.writeDigitRaw(1, 0x08)
	if predictionString2 == "null":
		print("no bus 2")		
		segment.writeDigitRaw(3, 0x08)
		segment.writeDigitRaw(4, 0x08)				

	# if predictionString contains anything but null
	if (predictionString != "null"):
		# if closest bus will arrive within current hour
		if (currentHours == predictionHours):
			minEstimate = int(predictionMins) - int(currentMins)
			print("first arrival in " + str(minEstimate))
			# if less than ten minutes, set first digit to zero
			if int(minEstimate) <= 9:
				segment.writeDigit(0, 0)			
				segment.writeDigit(1, minEstimate)
			# if more than ten minutes, figure both first and second digits
			if int(minEstimate) >= 10:
				segment.writeDigit(0, int(str(minEstimate)[0:1]))			
				segment.writeDigit(1, int(str(minEstimate)[1:2]))
				
		# if closest bus will arrive within the next hour
		# includes condition when next hour is tomorrow
		if (int(predictionHours) == int(currentHours) + 1) or (int(currentHours) == 24) and (int(predictionHours) == 0):
			minEstimate = int(predictionMins) + 60 - int(currentMins)
			print("first arrival in " + str(minEstimate))
			if int(minEstimate) <= 9:
				segment.writeDigit(0, 0)			
				segment.writeDigit(1, minEstimate)
			# if more than ten minutes, figure both first and second digits
Exemplo n.º 14
0
#    1 1   3    2    1    0
#    0 1   2    3    1    0

from Adafruit_7Segment import SevenSegment
import gaugette.rotary_encoder
import gaugette.switch
import math

segment = SevenSegment(address=0x70)
segment.disp.setBufferRow(0, 0)
segment.disp.setBufferRow(1, 0)
segment.disp.setBufferRow(2, 0)
segment.disp.setBufferRow(3, 0)
segment.disp.setBufferRow(4, 0)

segment.writeDigit(0, 1)
segment.writeDigit(1, 2)
#segment.writeDigit(2, 0);
segment.writeDigit(3, 3)
segment.writeDigit(4, 4)

if gaugette.platform == 'raspberrypi':
    A_PIN = 7
    B_PIN = 9
    SW_PIN = 8
else:  # beaglbone
    A_PIN = "P9_13"
    B_PIN = "P9_15"
    SW_PIN = "P9_11"

encoder = gaugette.rotary_encoder.RotaryEncoder(B_PIN, A_PIN)
        temp_in_F = (temp * 9.0 / 5.0) + 32.0

        print "Temperature: %.2f C" % temp
        print "Temperature: %.2f F" % temp_in_F
        print "Pressure:    %.2f hPa" % (pressure / 100.0)
        print "Altitude:    %.2f m" % altitude
        print "Press CTRL+C to exit"
        print ""

        for display_tmp_in_F in [False, True]:

            if display_tmp_in_F:
                if round(temp_in_F * 10.0) < 1000.0:
                    # write degrees
                    segment.writeDigit(0, int(round(temp_in_F) / 10))  # Tens
                    segment.writeDigit(1, int(round(temp_in_F) % 10))  # Ones
                    segment.writeDigit(3, int(int(round(temp_in_F * 10.0)) % 10))  # Tenth
                    segment.writeDigit(4, 15)  # F

                    segment.setColon(1)  #
                else:
                    # write degrees
                    segment.writeDigit(0, int(round(temp_in_F) / 100))  # Hundreds
                    segment.writeDigit(1, int(round(temp_in_F - 100.0) / 10))  # Tens
                    segment.writeDigit(3, int(round(temp_in_F) % 10))  # Ones
                    segment.writeDigit(4, 15)  # F

                    segment.setColon(0)

            else:
Exemplo n.º 16
0
  # Distance pulse travelled in that time is time
  # multiplied by the speed of sound (cm/s)
  distance = elapsed * 34300

  # That was the distance there and back so halve the value
  distance = distance / 2

  # Apply adjustment to tweak result
  distance = distance - adjustment
  if int(distance) > 99:
    show = int(distance)
    number_string = str(show)
    print "D: %s" %number_string
    for i in range(0,4):
      if i != 2 and i <= 3:
        segment.writeDigit(i, int(number_string[i]));

  else:
    show = '{0:.2f}'.format(round(distance,2))
    number_string = str(show)    
    if show > 10:
	      print "D: %s" %number_string
              segment.writeDigit(0, int(number_string[0]));
              segment.writeDigit(1, int(number_string[1]),True);
              segment.writeDigit(3, int(number_string[3]));
              segment.writeDigit(4, int(number_string[4]));
    else:
              segment.writeDigit(1, int(number_string[1]),True);
              segment.writeDigit(3, int(number_string[3]));
              segment.writeDigit(4, int(number_string[4]));
  
Exemplo n.º 17
0
		pygame.display.flip()

	#Wait for user's input to continue
	input = [not GPIO.input(22), not GPIO.input(17), not GPIO.input(21), not GPIO.input(4)]
	while 1 not in input:
		input =  [not GPIO.input(22), not GPIO.input(17), not GPIO.input(21), not GPIO.input(4)] #Each value is inverted since this is active low
	
#Application Entry Point
reset()
t1 = time.time()
t2 = time.time()
while True:
	if time.time() - t1 > 0.01:
		process_input()
		collision_check()
		output_frame()
		t1 = time.time()

	if time.time() - t2 > 0.5:
		for row_number in range(1,6):
			process_log_row(row_number)
		for row_number in range(7,12):
			process_car_row(row_number)
		segment.writeDigit(0, 0)
		segment.writeDigit(1, level)
		segment.writeDigit(3, 0)
		segment.writeDigit(4, number_of_lives)
		t2 = time.time()

		
import time
from Adafruit_7Segment import SevenSegment

segment0 = SevenSegment(address=0x70)
segment1 = SevenSegment(address=0x71)
segment2 = SevenSegment(address=0x72)
segment3 = SevenSegment(address=0x73)

for i in [0,1,3,4]:
    segment0.writeDigit(i, 8)

for i in [0,1,3,4]:
    segment1.writeDigit(i, 8)

for i in [0,1,3,4]:
    segment2.writeDigit(i, 8)

for i in [0,1,3,4]:
    segment3.writeDigit(i, 8)

Exemplo n.º 19
0
import Adafruit_BBIO.ADC as ADC
import time
import datetime
from Adafruit_7Segment import SevenSegment
segment = SevenSegment(address=0x70)
sensor_pin = 'P9_40'
ADC.setup()
while(True):
    reading = ADC.read(sensor_pin)
    millivolts = reading * 1800
    temp_c = (millivolts - 500) / 10
    segment.writeDigit(0, int(temp_c / 10))
    segment.writeDigit(1, int(temp_c % 10))
    segment.writeDigit(3, 12)
    segment.setColon(1)
    time.sleep(1)
Exemplo n.º 20
0
print "Press CTRL+Z to exit."

digit2_colon = 0x02
digit2_dot = 0x10
digit0 = 0

while(True):
  now = datetime.datetime.now()
  hour = now.hour
  minute = now.minute
  second = now.second
  dots = 0x0
  dots = dots^digit2_dot if (hour >= 12) else dots
  dots = dots^digit2_colon if (second % 2) else dots
  if hour == 0:
    hour = 12
  if hour > 12:
    hour = hour - 12
  if (hour >= 10 and digit0 == 0):
    segment.writeDigit(0, 1)
    digit0 = 1
  if (hour < 10 and digit0 == 1):
    segment.disp.clear()
    digit0 = 0
  segment.writeDigit(1, hour % 10)
  segment.writeDigitRaw(2, dots)
  segment.writeDigit(3, int(minute / 10))
  segment.writeDigit(4, minute % 10)
  time.sleep(0.25)

        temp_in_F = (temp * 9.0 / 5.0) + 32.0

        print "Temperature: %.2f C" % temp
        print "Temperature: %.2f F" % temp_in_F
        print "Pressure:    %.2f hPa" % (pressure / 100.0)
        print "Altitude:    %.2f m" % altitude
        print "Press CTRL+C to exit"
        print ""

        for display_tmp_in_F in [False, True]:

            if display_tmp_in_F:
                if round(temp_in_F * 10.0) < 1000.0:
                    # write degrees
                    segment.writeDigit(0, int(round(temp_in_F) / 10))     # Tens
                    segment.writeDigit(1, int(round(temp_in_F) % 10))          # Ones
                    segment.writeDigit(3, int(int(round(temp_in_F * 10.0)) % 10))   # Tenth
                    segment.writeDigit(4, 15)        # F
                    
                    segment.setColon(1)              # 
                else:
                    # write degrees
                    segment.writeDigit(0, int(round(temp_in_F) / 100))     # Hundreds
                    segment.writeDigit(1, int(round(temp_in_F - 100.0) / 10))      # Tens
                    segment.writeDigit(3, int(round(temp_in_F) % 10))      # Ones
                    segment.writeDigit(4, 15)        # F

                    segment.setColon(0)               

            else:
Exemplo n.º 22
0
  #       rollover from 23:59 or 11:59 back to zero. For convenience,
  #       keep track of previous_hours and then clear the display when
  #       the next hours is numerically < previous_time.
  previous_hours=25  # ensure display is initially cleared

  while(True):
    now = datetime.datetime.now()                       # load time into integer variables
    hour = int(now.hour)
    htens = hour/10
    minute = int(now.minute)
    second = int(now.second)

    if hour < previous_hours: segment.disp.clear(True)  # clear display when hour resets
    previous_hours = hour

    if htens>0: segment.writeDigit(af7s_digit1, htens)  # set hours tens (if non 0)
    segment.writeDigit(af7s_digit2, hour % 10)          # set hours units

    segment.writeDigit(af7s_digit3, minute / 10)        # set minutes
    segment.writeDigit(af7s_digit4, minute % 10)

    if second % 2 > 0:                                  # set/clear colon (other LEDs off)
      segment.disp.setBufferRow(af7s_ledRow, af7s_FLAGS[ 'colon' ] )
    else:
      segment.disp.setBufferRow(af7s_ledRow, af7s_FLAGS[ 'blank' ] )

    time.sleep(1)                                       # delay for 1 second

                                                        # exit with clear display
except KeyboardInterrupt:                               # with LED indicating event
  segment.disp.clear( True )
Exemplo n.º 23
0
  if (current == 0 and current_tick == 0):
      current = countdown
      current_tick = ticks
      
  # When the countdown is a 0, blink between zeros and eights
  if (current == 0 and current_tick % 2):
      minute = 88
      second = 88      

  # or simply show the time
  else:       
      minute = current / 60
      second = current % 60
  
  # Set minutes
  segment.writeDigit(0, int(minute / 10))     # Tens
  segment.writeDigit(1, minute % 10)          # Ones
  
  # Set seconds
  segment.writeDigit(3, int(second / 10))   # Tens
  segment.writeDigit(4, second % 10)        # Ones
  
  # Toggle colon
  segment.setColon(second % 2)              # Toggle colon at 1Hz
  
  # while the countdown is still 
  # running, decrement and wait 1 sec
  if (current > 0):
      current -= 1
      time.sleep(1)
      
Exemplo n.º 24
0
# ===========================================================================
segment = SevenSegment(address=0x70)

print "Press CTRL+Z to exit"
startmillis = int(round(time.time() * 1000))
# Continually update the time on a 4 char, 7-segment display
while(True):
  currentmillis = int(round(time.time() * 1000))
  # now = datetime.datetime.now()
  # hour = now.hour
  diff = LIMIT-int(currentmillis - startmillis)
  second = diff/1000
  minute = second/60
  
  if(minute>0):
    segment.writeDigit(0, int(minute / 10))     # Tens
    segment.writeDigit(1, minute % 10)          # Ones
    # Set minutes

    segment.writeDigit(3, int(second % 60 / 10 ))   # Tens
    segment.writeDigit(4, second % 60 % 10)        # Ones
    
  else:
    segment.writeDigit(0, int((diff / 1000)/10))    # Tens
    segment.writeDigit(1, int((diff / 1000)%10))          # Ones
    
    segment.writeDigit(3, int(diff / 100)%10 )   # Tens
    segment.writeDigit(4, int(diff % 10 ) )        # Ones
  # Toggle colon
  segment.setColon(second % 2)              # Toggle colon at 1Hz
  
#!/usr/bin/python

from Adafruit_7Segment import SevenSegment
import RPi.GPIO as io

#io.setmode(io.BCM)
segment = SevenSegment(address=0x70)

while True:
    position = raw_input('Position: ')
    if position == 'end': break
    elif position == 'clear':
        position = raw_input('Position: ')
        if position == 'all': segment.clear()
        else: segment.clear(int(position))
    else:
        number = raw_input('Number: ')
        'if len(number) == 1:'
        segment.writeDigit(int(position), int(number))
        'else: print ' 'Must be digit'
    print segment.getBuffer()
segment.clear()
Exemplo n.º 26
0
print datetime.datetime.now()
print API_data
print temp


# Continually update the time on a 4 char, 7-segment display
# 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
#     # Set minutes
#     segment.writeDigit(3, int(minute / 10))   # Tens
#     segment.writeDigit(4, minute % 10)        # Ones
#     # Toggle color
#     segment.setColon(second % 2)              # Toggle colon at 1Hz
#     # Wait one second
#     time.sleep(1)
#
while True:

    segment.writeDigit(0, int(temp / 10))
    segment.writeDigit(1, temp % 10)
    segment.writeDigitRaw(2, 0x2)
    segment.writeDigit(3, 8)
    segment.writeDigit(4, 8)
    time.sleep(10)
    break
Exemplo n.º 27
0
  elapsed = stop-start

  # Distance pulse travelled in that time is time
  # multiplied by the speed of sound (cm/s)
  distance = elapsed * 34300

  # That was the distance there and back so halve the value
  distance = distance / 2

  # Apply adjustment to tweak result
  distance = distance - adjustment

  # print "Distance : %.1f" % distance
  number_string = str(distance)

  now = datetime.datetime.now()
  second = now.second
  
  segment.writeDigit(0, number_string[0])
  segment.writeDigit(1, number_string[1])
  segment.writeDigit(3, number_string[2])
  segment.writeDigit(4, number_string[3])
  
  # Toggle color
  segment.setColon(second % 2)              # Toggle colon at 1Hz
  # Wait one second
  time.sleep(1)

  # Reset GPIO settings
GPIO.cleanup()
#!/usr/bin/python

from Adafruit_7Segment import SevenSegment
import time

segment = SevenSegment(address=0x70)
num = 0
rest = float(raw_input('Step: '))
while True:
    segment.setColon((num / 10000) % 2)
    segment.writeDigit(0, (num / 1000) % 10)
    segment.writeDigit(1, (num / 100) % 10)
    segment.writeDigit(3, (num / 10) % 10)
    segment.writeDigit(4, num % 10)
    num += 1
    time.sleep(rest)
Exemplo n.º 29
0
# Main function
setup()
global encount
global n
global _n
while True:
    startStop = startStop_debounce()
    reset = reset_debounce()
    if(startStop == True):
        encount = encount + 1
        print('start/stop button pressed: %d' % encount)
    if(reset == True):
        n = 0
        _n = 0
        # update 7 segement display
        segment.writeDigit(0, 0)
        segment.writeDigit(1, 0)
        segment.writeDigit(2, 0)
        segment.writeDigit(3, 0)
        segment.writeDigit(4, 0)
    if((encount & 1) == 1):
        GPIO.output(25, 1)           # turn on the status light on pin 25
        tick()
    else:
        GPIO.output(25, 0)           # turn off the status light on pin 25
    # update 7 segement display
    segment.writeDigit(0, (n / 60) / 10)
    segment.writeDigit(1, (n / 60) % 10)
    segment.writeDigit(2, n % 2)
    segment.writeDigit(3, (n % 60) / 10)
    segment.writeDigit(4, (n % 60) % 10)
Exemplo n.º 30
0
    #       the next hours is numerically < previous_time.
    previous_hours = 25  # ensure display is initially cleared

    while (True):
        now = datetime.datetime.now()  # load time into integer variables
        hour = int(now.hour)
        htens = hour / 10
        minute = int(now.minute)
        second = int(now.second)

        if hour < previous_hours:
            segment.disp.clear(True)  # clear display when hour resets
        previous_hours = hour

        if htens > 0:
            segment.writeDigit(af7s_digit1, htens)  # set hours tens (if non 0)
        segment.writeDigit(af7s_digit2, hour % 10)  # set hours units

        segment.writeDigit(af7s_digit3, minute / 10)  # set minutes
        segment.writeDigit(af7s_digit4, minute % 10)

        if second % 2 > 0:  # set/clear colon (other LEDs off)
            segment.disp.setBufferRow(af7s_ledRow, af7s_FLAGS['colon'])
        else:
            segment.disp.setBufferRow(af7s_ledRow, af7s_FLAGS['blank'])

        time.sleep(1)  # delay for 1 second

        # exit with clear display
except KeyboardInterrupt:  # with LED indicating event
    segment.disp.clear(True)
Exemplo n.º 31
0
import RPi.GPIO as GPIO
import time
import datetime
from Adafruit_7Segment import SevenSegment
import os

GPIO.setmode(GPIO.BCM)
segment = SevenSegment(address=0x70)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
pressed = False
while True:
    input_state = GPIO.input(18)
    if input_state == False:
        print('Button Pressed')
        segment.writeDigit(0, 0)
        segment.writeDigit(1, 0)
        segment.writeDigit(2, 0)
        segment.writeDigit(3, 1)
        time.sleep(0.2)
    else:
        segment.writeDigit(0, 0)
        segment.writeDigit(1, 0)
        segment.writeDigit(2, 0)
        segment.writeDigit(3, 2)
Exemplo n.º 32
0
        m_floor = math.floor(abs(temp_city))
        logging.debug('m_floor: %s', m_floor)

        hour_tens = int(m_floor / 10)
        logging.debug('hour_tens: %s', hour_tens)

        hour_ones = int(m_floor % 10)
        logging.debug('hour_ones: %s', hour_ones)

        min_tens = int("%.0f" % ((abs(temp_city) - m_floor) * 10))
        logging.debug('min_tens: %s', min_tens)

        if (negative_temp):
            min_ones = 0xE
        else:
            if (FAHRENHEIT):
                min_ones = 0xF
            else:
                min_ones = 0xC

    # Set hours
    segment.writeDigit(0, hour_tens)  # Tens
    segment.writeDigit(1, hour_ones, dot)  # Ones
    # Set minutes
    segment.writeDigit(3, min_tens)  # Tens
    segment.writeDigit(4, min_ones)  # Ones
    # Toggle colon
    segment.setColon(not dot and second % 2)  # Toggle colon at 1Hz
    # Wait one second
    time.sleep(1)
#!/usr/bin/python

import time
import datetime
from Adafruit_7Segment import SevenSegment

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

print("Press CTRL+Z to exit")

# Continually update the time on a 4 char, 7-segment display
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
  # Set minutes
  segment.writeDigit(3, int(minute / 10))   # Tens
  segment.writeDigit(4, minute % 10)        # Ones
  # Toggle colon
  segment.setColon(second % 2)              # Toggle colon at 1Hz
  # Wait one second
  time.sleep(1)
Exemplo n.º 34
0
        minute = 0

    if startstop and flg:
        flg = False
    if startstop and not flg:
        flg = True

    if not flg:
        sleep(1)
        print "stopped"
    else:
        a4 = counter % 10
        a3 = counter / 10
        a2 = minute % 10
        a1 = minute / 10
        segment.writeDigit(4, a4)
        segment.writeDigit(3, a3)
        # segment.writeDigit(1,a2)
        # segment.writeDigit(0,a1)
        segment.setColon(counter % 2)
        segment.writeDigit(1, a2)
        segment.writeDigit(0, a1)
        sleep(1)

        counter = counter + 1
        if counter == 60:
            counter = 0
            minute = minute + 1
    # now = datetime.datetime.now()
    # hour = now.hour
    # minute = now.minute
Exemplo n.º 35
0
os.system("sudo gpsd /dev/ttyUSB0 -F /var/run/gpsd.sock")

segment = SevenSegment(address=0x70)

# Ecouter sur le port 2947 (gpsd) de localhost
session = gps.gps("localhost", "2947")
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)

while True:
    try:
        report = session.next()
        if report['class'] == 'TPV':
            if hasattr(report, 'speed'):
                print report.speed
                vitesse = report.speed * 3.6
                segment.writeDigit(1, int(vitesse / 10))
                if int(vitesse % 10) == 0: segment.writeDigitRaw(3, 63 + 128)
                if int(vitesse % 10) == 1: segment.writeDigitRaw(3, 6 + 128)
                if int(vitesse % 10) == 2: segment.writeDigitRaw(3, 91 + 128)
                if int(vitesse % 10) == 3: segment.writeDigitRaw(3, 79 + 128)
                if int(vitesse % 10) == 4: segment.writeDigitRaw(3, 102 + 128)
                if int(vitesse % 10) == 5: segment.writeDigitRaw(3, 109 + 128)
                if int(vitesse % 10) == 6: segment.writeDigitRaw(3, 125 + 128)
                if int(vitesse % 10) == 7: segment.writeDigitRaw(3, 7 + 128)
                if int(vitesse % 10) == 8: segment.writeDigitRaw(3, 127 + 128)
                if int(vitesse % 10) == 9: segment.writeDigitRaw(3, 111 + 128)
                segment.writeDigit(4, int((vitesse * 10) % 10))  # Ones
    except KeyError:
        pass
    except KeyboardInterrupt:
        quit()
Exemplo n.º 36
0
  else:
    # Toggle colon
    segment.setColon(now.second % 2)              # Toggle colon at 1Hz

  minute = run_time.seconds / 60
  min_1 = int(minute / 10)
  min_2 = minute % 10
  second = run_time.seconds % 60
  sec_1 = int(second / 10)
  sec_2 = second % 10

  
  backpack.clear()
  # Set minutes
  if min_1 > 0:
    segment.writeDigit(0, min_1)     # Tens
  if min_1 + min_2 > 0:
    segment.writeDigit(1, min_2)     # Ones
  # Set minutes
  if min_1 + min_2 + sec_1 > 0:
    segment.writeDigit(3, sec_1)     # Tens

  segment.writeDigit(4, sec_2)       # Ones

  if(GPIO.input(BUTTON_GPIO) == 1):
    hold_time = hold_time + 1
  else:
    hold_time = 0

  if(hold_time == 4):
    timer_state = STOP
Exemplo n.º 37
0
#!/usr/bin/python

import time
import datetime
import Adafruit_BMP.BMP085 as BMP085

from Adafruit_7Segment import SevenSegment

segment = SevenSegment(address=0x70)

print "Press CTRL+Z to exit"

sensor = BMP085.BMP085()

presure=sensor.read_pressure()/100;


# Continually update the time on a 4 char, 7-segment display
while(True):
  presure=sensor.read_pressure()/100;
  print(presure)
  segment.writeDigit(0, int(str(presure)[0]),True)     
  segment.writeDigit(1, int(str(presure)[1]))          
  segment.writeDigit(3, int(str(presure)[2]))  
  segment.writeDigit(4, int(str(presure)[3]))                    
  # Wait one second
  time.sleep(1)

Exemplo n.º 38
0
        else:
            amTime = True

        if hour == 0:
            hour = 12

        minute = now.minute
        second = now.second

        #	Turn colon on
        sevenSeg.setColon(True)

        if displayCleared or (lastHour != hour):
            #	Set hours
            if hour > 9:
                sevenSeg.writeDigit(0, int(hour / 10))  # Tens
            else:
                #	Clear the 7 segment display
                sevenSeg.clear()
                displayCleared = True

            sevenSeg.writeDigit(1, hour % 10)  # Ones

        #	Only display if minute has changed or display was cleared
        if displayCleared or (lastMinute != minute):
            #	Set minutes
            sevenSeg.writeDigit(3, int(minute / 10))  # Tens
            sevenSeg.writeDigit(4, minute % 10)  # Ones

        #	Only display if time has changed from AM to PM or PM to AM, or the display was cleared
        if displayCleared or (lastAmTime != amTime):
import time
from Adafruit_7Segment import SevenSegment

REFRESH_INTERVAL = 1

print "Press CTRL+Z to exit"

while(True):

    segment0 = SevenSegment(address=0x70)
    segment1 = SevenSegment(address=0x71)
    segment2 = SevenSegment(address=0x72)
    segment3 = SevenSegment(address=0x73)

    for i in [0,1,3,4]:
        segment0.writeDigit(i, 0)

    for i in [0,1,3,4]:
        segment1.writeDigit(i, 1)

    for i in [0,1,3,4]:
        segment2.writeDigit(i, 2)

    for i in [0,1,3,4]:
        segment3.writeDigit(i, 3)
    
    time.sleep(REFRESH_INTERVAL)