示例#1
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()
示例#2
0
from tkinter import *
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import gdx, matplotlib.pyplot as plt, numpy as np, pygatt as pg

gdx = gdx.gdx()
pygatt = pg.pygatt()
gdx.open_ble()
pg.connect()
gdx.select_sensors()
root = Tk()


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)
示例#3
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()
示例#4
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()
示例#5
0
seconds_entry = Entry(root)
seconds_entry.grid()

samples_label = Label(root, text="How many samples should the sensor take per second?")
samples_label.grid()

samples_entry = Entry(root)
samples_entry.grid()

start_button = Button(root, text="Start Sensing", command=start_sensing)
start_button.grid()
 
# # #
gdx.open_usb()
gdx.select_sensors([2,3])

# # #
fig, ax = plt.subplots(1,1)
plt.ion()
chart = FigureCanvasTkAgg(fig,root)
chart.get_tk_widget().grid(column=1, row=0, rowspan=5 )

# # #
plt.title('Sensor Graphing ')
plt.xlabel('Time (Seconds)')
plt.ylabel('amu or something idk')

# # # # # #
root.mainloop()
gdx.stop()
示例#6
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)