Skip to content

Instantly share code, notes, and snippets.

app.post('/updateCounter', function (request, response){
// get current value
console.log('get current value');
counterDb.all('SELECT * from Counter ORDER BY id DESC LIMIT 1', function(err, row){
if(!err && row[0] && row[0].id){
const val = row[0].val;
console.log('value', val);
const id = row[0].id;
// store a new value
const sql = `UPDATE Counter SET val = ? WHERE id = ?`;
if(M5.BtnA.wasReleased() || M5.BtnB.wasReleased() || M5.BtnC.wasReleased()){
M5.Lcd.setTextSize(7);
M5.Lcd.println("button pressed");
// send an update to the Glitch app to increment the counter
counterHttp.begin("https://m5stack.glitch.me/updateCounter");
int counterHttpCode = counterHttp.POST("");
if(counterHttpCode > 0){
if(counterHttpCode == HTTP_CODE_OK){
uint16_t getFillColor(uint8_t r, uint8_t g, uint8_t b)
{
return ((r / 8) << 11) | ((g / 4) << 5) | (b / 8);
}
void loop()
{
M5.update();
// get the latest color
#include <WiFi.h>
const char* ssid = "YOURSSID";
const char* password = "YOURPW";
void setup()
{
M5.begin();
WiFi.disconnect();
delay(1000);
M5.Lcd.println("START");
app.post('/setColor', function(request, response){
console.log(request.body);
colorDb.run(`INSERT INTO Color VALUES ("${request.body.color}", "${Date.now()}")`, (error) => {
if(error){
response.send({message: 'error!'});
}else{
console.log('added color');
response.send({message: 'success'});
}
});
#include <WiFi.h>
#include <M5Stack.h>
#include <HTTPClient.h>
HTTPClient colorHttp;
HTTPClient counterHttp;
String tsData;
const char* ssid = "YOURSSID";
const char* password = "YOURPW";
@ttseng
ttseng / client.js
Last active May 19, 2018 06:38
Space Invaders
// client-side js
// run by the browser each time your view template is loaded
var player;
var playerSrc = "https://cdn.glitch.com/43e0016d-c8a0-4e4b-9451-241a4af8fb4f%2Fplayer.svg?1526019694966";
var invaderSrc = "https://cdn.glitch.com/43e0016d-c8a0-4e4b-9451-241a4af8fb4f%2Finvader.svg?1526019377700";
var dimension = 20; // base width and height for drawable objects
var canvasBound = 25;
var gameover = false;
@ttseng
ttseng / ffmpeg-ffmpegthumbnailer-heroku.md
Last active April 17, 2019 02:50 — forked from coopermaruyama/vendor-ffmpeg-heroku
install ffmpeg and ffmpegthumbnailer to your heroku app to use with carrierwave-video and carrierwave-video-thumbnailer

Preface

Below are the steps I took to install ffmpeg, ffmpegthumbnailer, and heroku to use with carrierwave-video and carrierwave-video-thumbnailer gems on my heroku app. I found there was no documentation to do exactly this, so I hope this is helpful for other people (and will save them the countless hours it took me to finally get it to work)

These are the libraries you will end up installing to get all of this to work.

  • x264