示例#1
0
def start_recording():
    seconds = int(seconds_entry.get())
    samples = int(samples_entry.get())
    axis = np.arange(0, seconds, 1 / samples)
    gdx.start(1000 // samples)
    red = []
    green = []
    blue = []
    # fig, ax = plt.subplots(1,1)
    ax.cla()

    for _ in range(seconds * samples):
        # print(gdx.read())
        vals = gdx.read()
        if vals == None:
            break
        r, g, b = vals
        red.append(r)
        green.append(g)
        blue.append(b)

    gdx.stop()

    print(axis)
    ax.plot(axis, red, color='r')
    ax.plot(axis, green, color='g')
    ax.grid()
    ax.plot(axis, blue, color='b')
    ax.legend(['r', 'g', 'b'])
    ax.set_title("Lights")
    ax.set_xlabel('Time (s)')
    ax.set_ylabel('lux')
示例#2
0
def start_sensing():
    
    measurements_list = []
    A_sensor_list = [] #0
    C_sensor_list = [] #1
    time_list = []
    time = 0
    #
    seconds = int(seconds_entry.get())
    samples = int(samples_entry.get())
    period = 1000 // samples
    #
    gdx.start(period=period)
    # #
    for i in range(seconds*samples):
        measurements = gdx.read()
        if measurements == None: 
            break 
        print(measurements)
        measurements_list.append(measurements)
    # #
    for line in measurements_list:
        A_sensor_list.append(line[0])
        C_sensor_list.append(line[1])
        time_list.append(time)
        time += 1/samples
    # #
    ax.clear()
    #
    plt.title('Sensor Graphing ')
    plt.xlabel('Time (Seconds)')
    plt.ylabel('amu or something idk')
    #
    ax.plot(time_list, A_sensor_list, c='skyblue')
    ax.plot(time_list, C_sensor_list, c='lightgreen')
示例#3
0
def take_sample():
    gdx.open_usb()
    gdx.select_sensors([5, 6, 7])
    gdx.start(period=1)
    sample = gdx.read()
    print(sample)
    gdx.stop()
    gdx.close()
示例#4
0
def start_reading():
    seconds = int(seconds_field.get())
    pers = int(samples_field.get())
    print(seconds, pers)

    gdx.start(period=1000 // pers)
    red = []
    green = []
    blue = []

    for i in range(seconds * pers):
        vals = gdx.read(
        )  #returns a list of measurements from the sensors selected.
        if vals == None:
            break
        red.append(vals[0])
        green.append(vals[1])
        blue.append(vals[2])
        print(vals)

    graph_data(seconds, pers, red, green, blue)
示例#5
0
def start_reading():
    seconds = int(seconds_field.get())
    samples = int(samples_field.get())
    sound_a, sound_c = [], []
    rate = 1000 // samples
    gdx.start(rate)
    interval = 1 / samples
    length = np.arange(0, seconds, interval)
    ax.cla()
    for i in range(samples * seconds):
        measure = gdx.read()
        sound_a.append(measure[0])
        sound_c.append(measure[1])
        if measure == None:
            break

    plt.yscale('linear')
    ax.plot(length, sound_a, c='red')
    ax.plot(length, sound_c, c='blue')
    plt.ylabel(ylabel='Sound(decibels)')
    plt.xlabel(xlabel='Time(seconds)')
    plt.show()
    gdx.stop()
示例#6
0
gdx.device_info()
gdx.enabled_sensor_info()
gdx.sensor_info()
gdx.discover_ble_devices()
monitor_rssi()

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Below is a simple starter program. Note that this program does not pass any 
arguments in the functions. Go to the gdx_getting_started_2.py example to 
see how you can pass arguments to the open(), select sensors(), and start() 
functions, and avoid the prompts.

**** This example assumes the Go Direct sensor is connected via USB.

'''
import gdx #the gdx function calls are from a gdx.py file inside the gdx folder.
gdx = gdx.gdx()

gdx.open_usb()
gdx.select_sensors()
gdx.start() 

for i in range(0,5):
    measurements = gdx.read() #returns a list of measurements from the sensors selected.
    if measurements == None: 
        break 
    print(measurements)

gdx.stop()
gdx.close()
示例#7
0
import gdx

seconds = int(input("How many seconds would you like: "))
pers = int(input("How many samples per second: "))

gdx = gdx.gdx()
gdx.open_usb()
gdx.select_sensors([5,6,7])
gdx.start(period = 1000//pers) 

for i in range(seconds * pers):
    measurements = gdx.read() #returns a list of measurements from the sensors selected.
    if measurements == None: 
        break 
    print(measurements)

gdx.stop()
gdx.close()
示例#8
0
import gdx
'''
In this example we are saving the data to a csv file to be opened with Excel.

'''

from gdx import gdx
gdx = gdx.gdx()

import csv

myFile = open('csvexample.csv', 'w', newline='')
writer = csv.writer(myFile)

gdx.open_usb()
gdx.select_sensors([1, 2])
gdx.start(period=500)
column_headers = gdx.enabled_sensor_info()
writer.writerow(column_headers)

for i in range(0, 5):
    measurements = gdx.read()
    if measurements == None:
        break
    writer.writerow(measurements)
    print(measurements)

gdx.stop()
gdx.close()
import gdx, time
import matplotlib.pyplot as plt

gdx = gdx.gdx()
# # #
seconds = int(input("How many seconds do you want to take samples for?"))
samples = int(input("How many samples do you want per second?"))
period = 1000 / samples

gdx.open_usb()
gdx.select_sensors([2, 3])
gdx.start(period=period)

# # #
for i in range(0, 5):
    measurements = gdx.read()
    if measurements == None:
        break
    print(measurements)

# # #
#for _ in range(time):
#

# # # # #
gdx.stop()
gdx.close()
示例#10
0
import turtle, tkinter as tk, random
import gdx

gdx = gdx.gdx()
screen = turtle.Screen()
game_over = False
jump = False
score = 0
game_over = False

gdx.open_usb()
gdx.select_sensors([1])
gdx.start(period=100)

def read_data():
    return gdx.read()
    screen.ontimer(read_data, 100)

def handle_jump():
    global jump, dino_dy, measure
    if not jump and measure[-1] >= 70:
        jump = True
        print('tyring to jump')
        dino_dy = 8
    screen.ontimer(handle_jump, 100)

def move_enemy():
    if jump:
        obstacle.back(20)
    else:
        obstacle.back(10)