Skip to content

Instantly share code, notes, and snippets.

View simonprickett's full-sized avatar
💭
I'm not your friend on Facebook.

Simon Prickett simonprickett

💭
I'm not your friend on Facebook.
View GitHub Profile
@simonprickett
simonprickett / carbonintensity.json
Created September 2, 2023 16:37
Example Carbon Intensity API output for the NG1 postcode in the East Midlands Region
{
"data": [
{
"regionid": 9,
"dnoregion": "WPD East Midlands",
"shortname": "East Midlands",
"postcode": "NG1",
"data": [
{
"from": "2023-09-02T16:00Z",
@simonprickett
simonprickett / carbonintensity.js
Created September 2, 2023 16:16
Embeddable JavaScript Demo - calling the UK Carbon Intensity API
// Swap NG1 for your postcode area...
const intensityAPIResponse = await fetch('https://api.carbonintensity.org.uk/regional/postcode/NG1');
const intensityData = await intensityAPIResponse.json();
const regionData = intensityData.data[0];
const forecastNum = regionData.data[0].intensity.forecast;
const forecastStr = regionData.data[0].intensity.index;
const generationMix = regionData.data[0].generationmix;
// Swap api-demo for the ID of the div that you want to render
// the results to on your page.
@simonprickett
simonprickett / flipdot_raspberry_pint.py
Created June 5, 2023 10:43
Flip dot Python example for Raspberry Pint meetup
from pyflipdot.pyflipdot import HanoverController
from pyflipdot.sign import HanoverSign
from serial import Serial
import random
import time
ser = Serial('/dev/ttyUSB0')
controller = HanoverController(ser)
sign = HanoverSign(address=6, width=84, height=7)
@simonprickett
simonprickett / flipdot_raspberry_pint.js
Last active June 5, 2023 10:44
Flip dots example with Node.js for Raspberry Pint talk
import FlipDot from 'flipdot-display';
const flippy = new FlipDot('/dev/ttyUSB0', 6, 7, 84);
async function sleep(millis) {
return new Promise((resolve) => {
setTimeout(resolve, millis);
});
}
flippy.once('open', async function() {
@simonprickett
simonprickett / main.rs
Last active November 28, 2021 16:57
Raspberry Pi Traffic Lights Example in Rust
use std::{thread, time};
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use ctrlc;
use rust_gpiozero::LED;
fn main() {
let keep_going = Arc::new(AtomicBool::new(true));
let kg = keep_going.clone();
@simonprickett
simonprickett / Program.cs
Created August 21, 2021 17:56
C# .NET code for Raspberry Pi GPIO Traffic Lights Article
using System;
using System.Device.Gpio;
using System.Threading;
namespace trafficlights
{
class Program
{
static void Main(string[] args)
{
void setup() {
M5.begin();
M5.M5Ink.clear();
InkPageSprite.creatSprite(0, 0, 200, 200);
drawScreen("Press to start!", 0);
playTone(1);
}
@simonprickett
simonprickett / pomodoro.c
Created June 6, 2021 16:47
Pomodoro Timer: Update an in progress timer.
if (currentState != STATE_IDLE) {
unsigned long timeNow = millis();
if (timeNow - startTime >= MILLIS_IN_ONE_MIN) {
minsRemaining--;
if (minsRemaining == 0) {
playTone(3);
// Work out what state comes next...
if (currentState == STATE_WORKING) {
@simonprickett
simonprickett / pomodoro.c
Created June 6, 2021 16:05
Power down the Pomodoro timer.
if (M5.BtnPWR.wasPressed()) {
drawScreen("Bye, love you!", 0);
playTone(1);
delay(3000);
M5.M5Ink.clear();
delay(1000);
currentState = STATE_IDLE;
M5.PowerDown();
}
void setup() {
M5.begin();
M5.M5Ink.clear();
InkPageSprite.creatSprite(0, 0, 200, 200);
drawScreen("Press to start!", 0);
playTone(1);
}