Skip to content

Instantly share code, notes, and snippets.

@blister
blister / index.js
Created July 18, 2023 21:00
JS Loop Speed Tests
const els = 10000000;
console.log('setup -> ' + els);
const opts = { 0: 'Fail!', 1: 'Publish!', 2: 'Publish!' };
let arr = [];
for ( let i = 0; i < els; ++i ) {
if ( Math.floor(Math.random() * 12) > 8 ) {
arr.push('good');
} else {
arr.push('bad');
}
@blister
blister / theremin.ino
Created February 18, 2019 02:49
Theremin Ranging Turnoff
void loop() {
// put your main code here, to run repeatedly:
long dist = msToCm(ping());
if ( dist < 100.00 ) {
toneCounter = 0;
// 1 == min distance in cm
// 100 == max distance in cm
// 1500 == max frequency
@blister
blister / theremin.ino
Created February 18, 2019 02:48
Theremin Ranging
void loop() {
// put your main code here, to run repeatedly:
long dist = msToCm(ping());
if ( dist < 100.00 ) {
toneCounter = 0;
// 1 == min distance in cm
// 100 == max distance in cm
// 1500 == max frequency
@blister
blister / theremin.ino
Created February 18, 2019 02:47
Theremin Setup
#define led 13
#define buzzer 3
#define echoPin A0
#define pingPin 10
int toneCounter = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
long ping() {
long duration;
// clear ping pin
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
void playNote(int note, int duration, float rest) {
digitalWrite(led, HIGH);
tone(buzzer, note, duration);
delay((duration * rest)/2);
digitalWrite(led, LOW);
delay((duration * rest)/2);
}
void loop() {
delay(50);
// See if an object is in front of us
int distance = msToCm(ping());
//Serial.println(distance);
if ( distance < detectionDistance ) {
// get a random song
playNote(NOTE_G5, 100, .1);
}
#include "Pitches.h"
/************************/
/** PIN CONFIGURATIONS **/
/************************/
#define led 13
#define buzzer 3
@blister
blister / GuardDog blink()
Created January 20, 2019 22:34
Guard Dog Tutorial for Robot Scholar