Skip to content

Instantly share code, notes, and snippets.

@MooseV2
Last active October 2, 2018 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MooseV2/29f3527ad7608c9e3175333e5552479a to your computer and use it in GitHub Desktop.
Save MooseV2/29f3527ad7608c9e3175333e5552479a to your computer and use it in GitHub Desktop.
// IEEEDay2018LED.ino
/* IEEE UOIT Student Branch IEEE Day workshop 2018 */
// Define the PWM pin connections -- these LEDs will connect...
// ...to the PWM connections of the Arduino with 220 Ohm resistors
int LED1 = 3;
int LED2 = 6;
int LED3 = 9;
// Declare variables
int LEDBrightness = 0;
int fadeStep = 6; // Number of fade points for the LED
// Setup code
void setup() {
// Define led pins as outputs
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
}
// Looping code -- runs forever
void loop() {
// Set the brightness of the LEDs, the analogWrite function uses PWM
analogWrite(LED1, LEDBrightness);
analogWrite(LED2, LEDBrightness);
analogWrite(LED3, LEDBrightness);
// Increment the brightness for each loop through
LEDBrightness = LEDBrightness + fadeStep;
// Flip the process to get it to dim again
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// delay to see the effects
delay(30);
}
// IEEEDay2018Servo.ino
/* IEEE UOIT -- IEEE Day Workshop 2018 */
#include <Servo.h> // Include the servo header file
Servo lServo; // Creates servo objects
Servo rServo;
void setup() {
Serial.begin(9600); // Begins communication through the serial monitor with baud rate of 9600
Serial.println("Servo control program started successfully");
lServo.attach(9); // Defines the pin the servos are connected to
rServo.attach(6);
}
void loop() {
direction = serial.readString();
if (direction == "Left" || direction == "left" || direction == "L" || direction == "l") {
lAngle = 0; // Sets servos to left position
rAngle = 180;
}
else if (direction == "Right" || direction == "right" || direction == "R" || direction == "r") {
lAngle = 180; // Sets servos to right position
rAngle = 0;
}
else if (direction == "straight" || direction == "Straight" || direction == "S" || direction == "s") {
lAngle = 90;
rAngle = 90;
}
else {
lAngle = 90; // Sets servos to neutral position -- if user does not specify direction it will default to straight
rAngle = 90;
}
lServo.write(lAngle); // Writes the angle to the servo range is 0 to 180
rServo.write(rAngle);
delay(2000); // Pause for servo rotation -- 2 seconds (2000 ms)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment