Skip to content

Instantly share code, notes, and snippets.

@peow2373
peow2373 / Digital_Input_and_Output.INO
Created February 10, 2020 19:37
Recognizes inputs from two different switch mechanisms and alters the color of a strip of Neopixels depending on which input is activated
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#define BUTTON_PIN 6 // Digital Input from Breadboard
#define BOARD_PIN 5 // Digital Input from Breakout Board
#define PIXEL_PIN 2 // Digital Output connected to the NeoPixels.
@peow2373
peow2373 / Digital_Read_Serial.INO
Last active February 10, 2020 19:41
Reads a digital input from a button on pin 2 and turns on two LEDs in series when the button is pressed
/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the Serial Monitor
http://www.arduino.cc/en/Tutorial/DigitalReadSerial
*/
// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;
@peow2373
peow2373 / Analog_Input_and_Output.INO
Created February 26, 2020 03:40
Demonstrates analog input through a potentiometer and a photoreceptor paired to dimming LED lights.
/*
Analog input, analog output, serial output
Reads an analog input pin, maps the result to a range from 0 to 255 and uses
the result to set the pulse width modulation (PWM) of an output pin.
Also prints the results to the Serial Monitor.
The circuit:
- potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
@peow2373
peow2373 / Tone_Output.INO
Created February 26, 2020 04:39
Uses an 8-bit speaker to create a tone output that changes frequency when the photoreceptor senses different amounts of lights
/*
Analog input, analog output, serial output
Reads an analog input pin, maps the result to a range from 0 to 255 and uses
the result to set the pulse width modulation (PWM) of an output pin.
Also prints the results to the Serial Monitor.
The circuit:
- potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
@peow2373
peow2373 / Analog_Input_and_Output_Enclosure.INO
Created February 26, 2020 04:43
Uses analog inputs from a potentiometer and a photoreceptor to open a door via servo motors and change Neopixels' colors
#include <Adafruit_NeoPixel.h>
#include <Servo.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
int analogInPin1 = A0; // Analog input pin that the potentiometer is attached to
int analogInPin2 = A1; // Analog input pin that the photoreceptor is attached to
int servoPin1 = 5; // Analog output pin
@peow2373
peow2373 / Arduino_to_p5.INO
Created March 11, 2020 06:21
Reads the values from two analog inputs and prints those values to the serial monitor
// These constants won't change. They're used to give names to the pins used:
int analogInPin1 = A0; // Analog input pin that the first potentiometer is attached to
int analogInPin2 = A1; // Analog input pin that the second potentiometer is attached to
int sensorValue1 = 0; // value read from the first potentiometer
int sensorValue2 = 0; // calue read from the second potentiometer
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
@peow2373
peow2373 / p5_to_Arduino.INO
Created March 11, 2020 06:23
Checks the serial monitor for incoming values to signal whether to turn an LED on or off
int LEDpin = 4;
int incomingByte;
void setup() {
pinMode(LEDpin, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
@peow2373
peow2373 / Fruit_Ninja.INO
Created March 11, 2020 06:56
Arduino code to receive x and y inputs from a joystick which is then communicated to the serial monitor. The code also checks for incoming values from the serial monitor to determine when to turn off the LEDs.
// These constants won't change. They're used to give names to the pins used:
int xAxis = A0; // Analog input pin that the x-axis of the joystick is attached to
int yAxis = A1; // Analog input pin that the y-axis of the joystick is attached to
int sensorValue1 = 0; // value read from the potentometer
int sensorValue2 = 0; // calue read from the photoreceptor
int LEDpin1 = 4;
int LEDpin2 = 7;
int LEDpin3 = 8;
@peow2373
peow2373 / DC_Motor_Control.INO
Created April 15, 2020 05:34
Swaps the direction in which a DC motor is rotating when a switch has a HIGH input
const int switchPin = 2; // switch input
const int motor1Pin = 3; // H-bridge leg 1 (pin 2, 1A)
const int motor2Pin = 4; // H-bridge leg 2 (pin 7, 2A)
const int enablePin = 9; // H-bridge enable pin
void setup() {
// set the switch as an input:
pinMode(switchPin, INPUT);
// set all the other pins you're using as outputs:
@peow2373
peow2373 / Stepper_Motor_Control.INO
Created April 15, 2020 05:44
Makes a stepper motor rotate one revolution at a time, before pausing, and then rotating again
#include <Stepper.h>
const int stepsPerRevolution = 64; // change this to fit the number of steps per revolution
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);