Skip to content

Instantly share code, notes, and snippets.

@GreenMoonArt
GreenMoonArt / Stepper Motor Back and Forth
Last active May 7, 2022 13:55
Stepper Motor Back and Forth
// tutorial
// https://www.makerguides.com/a4988-stepper-motor-driver-arduino-tutorial/
#include <AccelStepper.h>
// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver:
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1
@GreenMoonArt
GreenMoonArt / NeoPixel_MeasuringStick.ino
Created November 24, 2020 20:14
NeoPixel measuring stick using an ultrasonic distance sensor
// Measuring Stick
// Light up neopixel strip proportional to distance sensor reading
#include <Adafruit_NeoPixel.h>
#define LED_PIN 6
#define LED_COUNT 10
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
int trigPin = 12;
int echoPin = 13;
@GreenMoonArt
GreenMoonArt / Blink 2 LEDs Randomly with Timer
Last active September 23, 2020 15:37
Use a timer (no delays) to randomly blink 2 LEDs.
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
@GreenMoonArt
GreenMoonArt / Light Sensor and Timing Control
Created December 26, 2019 17:09
Light Sensor and Timing Control
/*
* Use a LDR as a light sensor to turn on things (LEDs, motors, etc) when it gets dark.
* After a given time period, have them turn off (while it's still dark).
* Daylight resets the system as it waits for nightfall, to begin again.
*/
unsigned long currentTime;
unsigned long loopTime;
unsigned long blinkTimer = (unsigned long)250;
// Need to cast each operand, otherwise the math is not correct:
@GreenMoonArt
GreenMoonArt / NeoPixel_Random_Colors
Last active May 6, 2019 16:44
ATTiny85 NeoPixel Ring After Dark with Randomized Colors and Sparkle Effect
// Originally copied from Becky Stern https://www.tinkercad.com/things/hMoLHIEK0Ny-neopixel-strip
// Modified to add reverse direction and adapted to ATTiny85
// Added photoresistor to activate at night time
// For randomized sparkle effect, refer to "Sipping Power With NeoPixels" guide.
// https://learn.adafruit.com/sipping-power-with-neopixels/demo-code
// This circuit can be viewed and simulated at:
// https://www.tinkercad.com/things/8dXZVFS18mn-attiny85-neopixel-after-dark-randomized-colors-sparkle-effect
#include <Adafruit_NeoPixel.h>
@GreenMoonArt
GreenMoonArt / ConcurrentBlinkingLEDs.ino
Last active June 28, 2018 22:42
Concurrent blinkind LEDs using millis()
//answering a question from StackExchange:
//https://arduino.stackexchange.com/questions/53976/too-few-arguments-for-multiple-if-statement-conditions/53979#53979
// Blue LED blinks
// Red LED should go on if Blue LED is ON and switch/button is in correct posistion
// Concurrent LED blinking code from here: https://learn.adafruit.com/multi-tasking-the-arduino-part-1/using-millis-for-timing
int redLEDPin = 7;
int blueLEDPin = 3;
int redLEDtiming = 250;
int blueLEDtiming = 2000;
@GreenMoonArt
GreenMoonArt / Ultrasonic Range Finder
Last active August 15, 2017 00:39
Ultrasonic Range Finder
int trigPin = 12;
int echoPin = 13;
void setup()
{
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
@GreenMoonArt
GreenMoonArt / Faerie_Twinkle.ino
Last active December 30, 2016 15:06
Random Individual NeoPixels, color, delay
/*
Blink NeoPixels randomly: vary color and on/off timing
by @GreenMoonArt
*/
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define numPIXELS 8
#define numCOLORS 7
@GreenMoonArt
GreenMoonArt / Dripping Icicles with NeoPixels
Last active October 4, 2020 14:10
Code to similuate dripping icicles using Arduino and several NeoPixel strips
/*
* Code to similuate dripping icicles using Arduino and multiple NeoPixel strips
* be sure to weatherize if you are putting this outdoors
*/
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif