Last active
April 5, 2017 18:15
-
-
Save mikrobitti-rakentelija/91e017a249f6d4546bb17291f9f3c881 to your computer and use it in GitHub Desktop.
Parkkikiekko - Testikoodit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Mikrobitin parkkikiekko. Ledirenkaan kokeilemiseen | |
* tarkoitettu testikoodi pyörittää ledeissä sinistä | |
* "poliisivaloa* | |
*/ | |
#include <FastLED.h> | |
#define NUM_LEDS 24 | |
#define DATA_PIN 6 | |
CRGB leds[NUM_LEDS]; | |
uint8_t position = 0; | |
void setup() { | |
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); | |
} | |
void loop() { | |
fadeToBlackBy(leds, NUM_LEDS, 64); | |
position++; | |
position = position % NUM_LEDS; | |
leds[position] = CRGB::Blue; | |
FastLED.show(); | |
delay(10); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python-kripti sarjaporttimittausten kirjoittamiseen | |
# InfluxDB-tietokantaan. Koodin on esimerkkinä | |
# sarjaporttiliikenteen lukemisesta koneellisesti. Tämä | |
# koodi vaatii InfluxDB-tietokannan käytön, mutta vastaavalla | |
# tavalla tiedot voisi kirjoittaa myös tiedostoon. | |
# | |
# | |
# Käyttöohje | |
# - Asenna pip-työkalulla kirjastot pyserial ja requests | |
# - Tarkista sarjaportin ja tietokannan asetukset | |
# - Aja komennolla python serial_influxdb_bridge.py | |
# | |
import serial | |
import requests | |
import time | |
measurement_names = ["x","y", "z","Gx","Gy","Gz","total"] | |
ser = serial.Serial('COM3', 57600) | |
ser.flushInput() | |
ser.flushOutput() | |
lines = [] | |
while True: | |
data_raw = ser.readline() | |
splitted = data_raw.split("\t") | |
if len(splitted) == 8: | |
values = [] | |
for i in range(0, 8): | |
values.append("{}={}".format(measurement_names[i],splitted[i])) | |
joined_values = ",".join(values) | |
timestamp = int(time.time() * 1000000000) | |
line = "accelerometer,unit=1 {} {}".format(joined_values, timestamp) | |
lines.append(line) | |
if len(lines) > 100: | |
print("sending") | |
payload = "\n".join(lines) | |
lines = [] | |
res = requests.post("http://localhost:8086/write?db=accelerometer", data=payload) | |
print(res.status_code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment