Skip to content

Instantly share code, notes, and snippets.

View futureshocked's full-sized avatar

Peter Dalmaris futureshocked

View GitHub Profile
/* <--- Arduino SbS Simple String Parser example --->
*
* This sketch shows how to receive a String from the serial
* monitor and parse it so that the first and second characters
* are returned. Once you have this information, you can use
* it to control connected devices, like an array of LEDs.
*
* For example, if you type '03O' (letter 'O'), the parses
* will detect '3' as the pin number and 'O' as the
* command, and will turn On an LED conected to digital pin 3.
/*
2. Blink
3. Turns on an LED on for one second, then off for one second, repeatedly.
4. Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
5. it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
6. the correct LED pin independent of which board is used.
7. If you want to know what pin the on-board LED is connected to on your Arduino model, check
8. the Technical Specs of your board at https://www.arduino.cc/en/Main/Products
@futureshocked
futureshocked / rgbled_simplified.ino
Created March 27, 2018 00:50
A simplified version of the example sketch that comes with the RGBLED library
#include "RGBLED.hpp"
// Pin mapping for the first RGBLED object:
const byte redLed = 3;
const byte greenLed = 5;
const byte blueLed = 6;
// The RGBLED object defaults to common cathode configuration.
RGBLED rgbLed(redLed, greenLed, blueLed);
void setup() {
@futureshocked
futureshocked / LBD3-MP1.ino
Created June 4, 2018 06:30
My solution to mini project 1 Day 4
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
make_it_blink();
}
@futureshocked
futureshocked / _0500_-_Infrared_Sensor_2.ino
Created June 24, 2018 02:11
This sketch demonstrates the use of the PIR infrared motion sensor.
/* Infrred sensor demo sketch
*
* This sketch demonstrates the use of the PIR infrared motion sensor.
*
* The sketch adds to the bare minimum version by allowing extra time
* after the sensor goes LOW for the LED to remain HIGH. This could be
* useful in a scenario where you want a light to go on in a room when
* someone enters it, but to turn of a few minutes after they leave it.
*
* This sketch was adapted from the original that comes with the
@futureshocked
futureshocked / detachInterrupt_example.ino
Created September 29, 2018 03:31
This is an example of how to use detachInterrupt with a rotary encoder
//Original sketch: https://bigdanzblog.wordpress.com/2014/08/16/using-a-ky040-rotary-encoder-with-arduino/
//Modified by Peter Dalmaris, July 2015
const int PinCLK=2; // Used for generating interrupts using CLK signal
const int PinDT=3; // Used for reading DT signal
const int PinSW=8; // Used for the push button switch
volatile long virtualPosition =0; // must be volatile to work with the isr
@futureshocked
futureshocked / spiffs.ino
Last active April 18, 2019 23:15
An example gist
#include "FS.h"
#include "SPIFFS.h"
// a change
/* You only need to format SPIFFS the first time you run a
test or else use the SPIFFS plugin to create a partition
https://github.com/me-no-dev/arduino-esp32fs-plugin */
#define FORMAT_SPIFFS_IF_FAILED true
@futureshocked
futureshocked / 101_datalogger
Created July 1, 2019 00:22
Arduino 101 datalogger example
// Written by Peter Dalmaris.
// This is an example of how to record data from the Arduino 101 accelerometer to an SD card
// Part of a demonstration for the Arduino Bootcamp for Teachers Extension Project
#include <SPI.h>
#include <SD.h>
#include "CurieIMU.h"
const int chipSelect = 4;
@futureshocked
futureshocked / ESP32_timer_interrupt_change_dureation.ino
Created July 20, 2019 05:46
ESP32 timer interrupts, how to change duration in the loop.
const byte LED_GPIO = 2;
volatile int interruptCounter; // When this is not zero, we'll take a reading from the sensor
// The interrupt service routine will increment it.
// When the sensor is read, this variable is decremented.
volatile int blinkCounter = 0;
// The hardware timer pointer
hw_timer_t * timer = NULL;
@futureshocked
futureshocked / parser.ino
Created July 24, 2019 07:02
Simple URL parser
void setup() {
Serial.begin(9600);
while (!Serial)
{}
// put your setup code here, to run once:
String str = "GET /?led06=1";
int led_index = str.indexOf("led");
int equal_index = str.indexOf("=");