Skip to content

Instantly share code, notes, and snippets.

- # Find the index of the blob with the most pixels.
- most_pixels = 0
- largest_blob = 0
- for i in range(len(blobs)):
- if blobs[i].pixels() > most_pixels:
- most_pixels = blobs[i].pixels()
- largest_blob = i
+ # Find the blob with the most pixels.
+ largest_blob = max(blobs, key=lambda b: b.pixels())
@seth10
seth10 / 11-KeyboardLEDs.py
Created July 10, 2017 12:04
Functional programming example on the PiStorms
from PiStorms import PiStorms
from TouchScreenInput import TouchScreenInput
from functools import partial
psm = PiStorms()
textbox = TouchScreenInput(psm.screen)
textbox.bind_led_on_func(partial(psm.led, 1, 255, 0, 0))
textbox.bind_led_off_func(partial(psm.led, 1, *[0]*3))
result = textbox.getInput()
psm.screen.showMessage(['Your answer', result['response']])
@seth10
seth10 / PiStorms_Development.sh
Last active June 27, 2017 20:06
A script to link files in /home/pi/PiStorms to their corresponding locations in the system
b=`grep homefolder /usr/local/mindsensors/conf/msdev.cfg | cut -d"=" -f2 | cut -c 2-`
for f in 'MSDriver.py' 'MSBrowser.py' 'psm_shutdown' 'swarmserver' 'pistorms-diag.sh'; do sudo ln -f $b/sys/$f /usr/local/bin/$f; done
chmod +x $b/sys/swarmserver $b/sys/pistorms-diag.sh $b/programs/addresschange
for f in 'rmap.py' 'rmapcfg.py' 'scratch.py' 'PiStorms.py' 'PiStormsCom.py' 'TouchScreenInput.py' 'mindsensorsUI.py' 'MS_ILI9341.py' 'mindsensors.py' 'MsDevices.py' 'LegoDevices.py' 'swarmclient.py'; do sudo ln -f $b/sys/$f /usr/local/lib/python2.7/dist-packages/$f; done
sudo rm -rf /var/www
sudo ln -s $b/www /var/www
sudo ln -f $b/sys/msdev.cfg /usr/local/mindsensors/conf/msdev.cfg
# skipping images, art, scratch, changing ownerships... programs are still only in /home/pi/PiStorms
for f in 'MSDriver.sh' 'MSBrowser.sh' 'MSWeb.sh' 'SwarmServer.sh'; do sudo ln -f $b/setup/$f /etc/init.d/$f; done
for f in 'MSDriver.sh' 'MSBrowser.sh' 'MSWeb.sh' 'SwarmServer.sh'; do chmod +x $b/setup/$f; done
@seth10
seth10 / randomWord.py
Last active May 13, 2017 21:20
Reads the standard system dictionary file and prints a random word
with open("/usr/share/dict/words") as f:
dict = [word.rstrip('\n') for word in f]
import random
print random.choice(dict)
# or, a one-liner
random.choice(open("/usr/share/dict/words").readlines())[:-1]
# in an isolated environment:
+-1
--1
-----1
+++++1
++++++++--------1
1*-+-+-+-+-+-+-+-+-+-+-+-1*-+1/+-+-+-+-+-1
@seth10
seth10 / clcp_sd540c.sh
Last active May 12, 2017 13:36
bash brace expansion is fun
admin@roboRIO-1086-FRC:~$ clcp_sd540c scan
{"scan":[10,12,13,15,16,17,18]}
admin@roboRIO-1086-FRC:~$ for id in 1{0,2,3,{5..8}}; do clcp_sd540c $id name; done
status: 0
{"name":"GreenTen"}
status: 0
{"name":"YellowTw"}
status: 0
{"name":"GreenThi"}
status: 0
@seth10
seth10 / slyt277.py
Last active May 12, 2017 13:35
Calibration based on TI's paper, www.ti.com/lit/SLYT277
import numpy as np
from PiStorms import PiStorms
def calibrate(psm):
def generateA(X,Y):
for (x,y) in zip(X,Y):
psm.screen.fillRect(x,y, 1,1, (255,0,0))
while psm.isKeyPressed(): pass # wait until the button is released from a possible previous press
while not psm.isKeyPressed(): pass # wait until the key is pressed down again
tsX = int(psm.screen.RAW_X()) # mindsensors_i2c.readInteger should really already return an integer
<html>
<title>CSS3 Animations Examples</title>
<head>
<style>
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes fadeInUp {
@seth10
seth10 / 00-Keyboard.py
Last active May 11, 2017 20:40
TouchScreenInput partial
from PiStorms import PiStorms
from TouchScreenInput import TouchScreenInput
from functools import partial
psm = PiStorms()
textbox = TouchScreenInput(psm.screen)
textbox.bind_led_on_func(partial(psm.led, 1, 255, 0, 0))
textbox.bind_led_off_func(partial(psm.led, 1, *[0]*3))
result = textbox.getInput()
psm.screen.showMessage(['Your answer', result['response']])
@seth10
seth10 / warnings.log
Created May 11, 2017 19:57
Warnings generated by Doxygen for undocumented members in PiStorms/sys
LegoDevices.py:298: Compound LegoDevices::EV3ColorSensor
swarmclient.py:60: Compound swarmclient::SwarmClient
LegoDevices.py:347: Compound LegoDevices::EV3InfraredSensor
LegoDevices.py:311: Compound LegoDevices::EV3GyroSensor
LegoDevices.py:257: Compound LegoDevices::NXTLightSensor
PiStormsCom.py:33: Compound PiStormsCom::PSSensor
MS_ILI9341.py:31: Compound MS_ILI9341::ILI9341
LegoDevices.py:199: Compound LegoDevices::EV3TouchSensor
scratch.py:9: Compound scratch::Scratch
LegoDevices.py:330: Compound LegoDevices::EV3UltrasonicSensor