def write_to_display(message, brightness=1): if i2c_present: clear() set_brightness(brightness) write_string(message.rjust(6), kerning=False) show() else: print(message)
def dimmer(): notte = datetime.datetime.now() orario_notte = notte.time() if orario_notte >= datetime.time(20, 00) or orario_notte <= datetime.time( 8, 00): set_brightness(0.5) else: set_brightness(1)
def print_string_fade(text): start = time.time() speed = 3 shown = True b = 0 while shown: b = (math.sin((time.time() - start) * speed) + 1) / 2 microdotphat.set_brightness(b) if b < 0.002 and shown: microdotphat.clear() microdotphat.write_string(text, kerning=False) microdotphat.show() shown = False if b > 0.998: shown = True time.sleep(0.01)
import strava import datetime import time from microdotphat import set_brightness, write_string, set_decimal, clear, show st = strava.Strava() set_brightness(0.1) while True: clear() t = datetime.datetime.now() if t.second > 10: if t.second % 2 == 0: set_decimal(2, 1) set_decimal(4, 1) else: set_decimal(2, 0) set_decimal(4, 0) write_string(t.strftime("%H%M%S"), kerning=False) else: total_distance = "{:6.0f}".format(st.get_total_distance()) write_string(total_distance, kerning=False) show() time.sleep(1)
speed = 5 strings = ["One", "Two", "Three", "Four"] string = 0 shown = True show() # Start time. Phase offset by math.pi/2 start = time.time() while True: # Fade the brightness in/out using a sine wave b = (math.sin((time.time() - start) * speed) + 1) / 2 set_brightness(b) # At minimum brightness, swap out the string for the next one if b < 0.002 and shown: clear() write_string(strings[string], kerning=False) string += 1 string %= len(strings) show() shown = False # At maximum brightness, confirm the string has been shown if b > 0.998: shown = True
dest='trend', choices=['UP', 'up', 'down', 'DOWN'], help='The optional cost trend - case determines strength', default='flat') # Optional display brightness PARSER.add_argument('--brightness', dest='brightness', metavar='<0.0 - 1.0>', help='The display brightness to set, in range 0.0..1.0', type=float) # Optionally clear the display - this takes precedence PARSER.add_argument('--clear', dest='clear', action='store_true', help='Clear the display - takes precedence over other options') ARGS = PARSER.parse_args() if ARGS.clear: md.set_clear_on_exit(True) else: if ARGS.brightness: md.set_brightness(ARGS.brightness) if ARGS.cost: update_display(ARGS.cost, ARGS.trend) md.set_clear_on_exit(False)
def set_brightness(value): microdotphat.set_brightness(value)
for i in xrange(1, len(bins)): if bins[i] <= bins[i - 1]: bins[i] = bins[i - 1] + 1 print bins # weighting maxWeight = 32 scaleF = float(maxWeight - 1) / pow(gamma, noBins - 1) weighting = (np.array([scaleF * pow(gamma, x) + 1 for x in xrange(noBins)])) weighting = np.divide(weighting, 50000) print weighting mdp.set_brightness(1.0) def sigIntHandler(signalNo, frame): # clean up inStream.stop_stream() inStream.close() p.terminate() sys.exit(0) signal.signal(signal.SIGINT, sigIntHandler) while True: rawsamps = inStream.read(chunkSize, False) # Convert raw data to NumPy array
clear() # messaggio di benvenuto # kerning=false fa vedere ogni carattere in un display separato write_string("Avvio!", kerning=False) show() time.sleep(3) #accendo tutti i punti della matrice (cosi' vedo anche se c'e' un guasto) fill(1) show() #faccio degradare la luminosita dal massimo al minimo a un millesimo per volta luminosita = 1 while luminosita > 0.001: luminosita = luminosita - 0.001 set_brightness(luminosita) #pausa di mezzo secondo, se no non si vede che il display si e' spento time.sleep(0.5) # imposto il tempo di switch tra le verie informazioni # il numero equivale alla q.ta di cicli con una pauda di 0,05'' per ogni ciclo tempo_switch = 50 clear() show() #imposto la luminosita al massimo set_brightness(1) #imposto i testi di data in Italiano locale.setlocale(locale.LC_ALL, "it_IT.UTF-8")