RAPPAHANNOCK COMMUNITY COLLEGE STEM CAMP
  • Home
  • 2021 STEM Camp (HS)
    • PreAcademy prep
    • Day 1: Basics, Lights, and Temperature Sensor >
      • Day 1 Supplement: Measure Temperature
      • Day 1 Supplement: IR Temp Sensor
      • Day 1 Supplement: Identifying Resistors
      • Supplement: Controlling Buttons
      • Supplement: Controlling A Servo
    • Day 2: Measuring Pulse >
      • How the body absorbs light
      • Day 2 Supplement: IR Light Proximity Sensor
      • Day 2 Supplement: Motion Sensor
      • Code to start later on plotter
    • Day 3 Supplement: OLED Screen Basics >
      • Display Screen Temperature
      • IR Temp Sensor And Screen
      • Scrolling Screen Graph
    • Day 4: Finishing up/Show >
      • Pictures to OLED
      • BPM Pulse Sensor
      • Multimeter
  • Shared Google Folder
  • The Teachers
  • Archive
    • Pictures from prior years
    • 2021 STEM Camp (MS) >
      • Home (2021)
      • PreAcademy prep
      • Day 1: Basics, Lights, and Temperature Sensor >
        • Day 1 Supplement: Identifying Resistors
        • Day 1 Supplement: Measure Temperature
        • Day 1 Supplement: IR Light Proximity Sensor
      • Day 2: Ultrasound >
        • Day 2 Supplement: IR Temp Sensor
        • Day 2 Supplement: Controlling A Servo
      • Day 3: Measuring Pulse >
        • Day 3 Supplement: Motion Sensor
      • Day 4: OLED Screen Basics >
        • Temperature Screen Display
        • IR Temp Sensor And Screen
      • Day 5 Friday: Finishing up/Show
    • 2020 STEM Camp >
      • Home (2020)
      • The 2020 Teachers
      • PreAcademy prep
      • Day 1 Monday: Basics and Lights >
        • Day 1 Supplement Activity
      • Day 2 Tuesday: Servos >
        • Day 2 (Suppliment Activities)
      • Day 3 Wednesday: Making an ECG/EKG! >
        • Day 3 (Supplement Page)
      • Day 4 Thursday: Controlling Servos with EMG >
        • Day 4 Supplemental Activity
      • Day 5 Friday: Finishing up/Show >
        • Unused lessons/content
    • 2018 Lessons >
      • Day 1: Basic Coding
      • Day 2: Motors
      • Day 3: Build Robot Claw
      • Day 4: Saving Positions
      • Day 5: Presentations
    • 2017 Camp >
      • Day 1 (Monday)
      • Day 2: Multicolor LED and Keypad
      • Day 3: Servo and Keypad
      • Day 4: Multiple Motors/Stepper Motor
      • Day 5: Presentations
    • Pictures archive for lessons (some graphic images)
  • Contact Us!

This page is under development :P

This page is just a bunch of random code that was not directly used in the camp. 

Getting the colors to fade

See if you can get your RGB LED to fade in and out with this code. Let's see if we can understand it too. 

#define BLUE 3 //We are defining the different colors
#define GREEN 5 //to the different pins 
#define RED 6 // change the numbers to what you have plugged in
​
void setup(){
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, LOW);
}
int redValue; // define variables
int greenValue;
int blueValue;

void loop(){
#define delayTime 10 // fading time between colors

redValue = 255; // this code starts with red on, choose a value between 1 and 255 to change the color.
greenValue = 0;
blueValue = 0;

for(int i = 0; i < 255; i += 1) { // fades out red bring green full when i=255
redValue -= 1; // makes red dimmer by one each delay time 
greenValue += 1; // makes green brighter by one each delay time 
analogWrite(RED, redValue);
analogWrite(GREEN, greenValue);
delay(delayTime);
}

for(int i = 0; i < 255; i += 1) { // fades out green bring blue full when i=255
greenValue -= 1;
blueValue += 1;
analogWrite(GREEN, greenValue);
analogWrite(BLUE, blueValue);
delay(delayTime);
}

for(int i = 0; i < 255; i += 1) {// fades out blue bring red full when i=255
blueValue -= 1;
redValue += 1;
analogWrite(BLUE, blueValue);
analogWrite(RED, redValue);
delay(delayTime);
 }
}
Once you get the one LED code to work, try to figure out how to get more lights to work with buttons if you have time. 
You basically just have to add an extra line to each part and name new variables for the new lights. 
Look at the difference between the code above and below to try and figure out the pattern for adding more parts. ​
Picture

Turning onboard LED on and off with Button

We will now try to get that onboard LED to blink by using a button. Set up your circuit similar to below
Use the :
  • 10K ohm resistor
Picture
​// This code turns on and off a light emitting diode(LED) connected to digital
//pin 13, when pressing a push-button attached to pin 2.

// the below sets pin numbers: const is used before int to ensure the value does not change

const int buttonPin=2;          //the number of the pushbutton pin
const int ledPin=LED_BUILTIN;     //the number of the LED pin 
int buttonState=0; // variable for reading the pushbutton status


void setup() {
pinMode (ledPin,OUTPUT);
pinMode (buttonPin,INPUT);
}
void loop() {
buttonState=digitalRead(buttonPin);
if(buttonState==HIGH){
digitalWrite(ledPin,HIGH);
 }
else{
  digitalWrite(ledPin,LOW);
 }
}
Could you get this code to control one servo? 
Once you do, show your teacher and then try to change the code so that it can control more than one servo by potentiometers. You basically just copy each part of the code and add extra lines with different numbers. 
Here is an example with 4 potentiometer dials. 
Picture
Picture
Powered by Create your own unique website with customizable templates.
  • Home
  • 2021 STEM Camp (HS)
    • PreAcademy prep
    • Day 1: Basics, Lights, and Temperature Sensor >
      • Day 1 Supplement: Measure Temperature
      • Day 1 Supplement: IR Temp Sensor
      • Day 1 Supplement: Identifying Resistors
      • Supplement: Controlling Buttons
      • Supplement: Controlling A Servo
    • Day 2: Measuring Pulse >
      • How the body absorbs light
      • Day 2 Supplement: IR Light Proximity Sensor
      • Day 2 Supplement: Motion Sensor
      • Code to start later on plotter
    • Day 3 Supplement: OLED Screen Basics >
      • Display Screen Temperature
      • IR Temp Sensor And Screen
      • Scrolling Screen Graph
    • Day 4: Finishing up/Show >
      • Pictures to OLED
      • BPM Pulse Sensor
      • Multimeter
  • Shared Google Folder
  • The Teachers
  • Archive
    • Pictures from prior years
    • 2021 STEM Camp (MS) >
      • Home (2021)
      • PreAcademy prep
      • Day 1: Basics, Lights, and Temperature Sensor >
        • Day 1 Supplement: Identifying Resistors
        • Day 1 Supplement: Measure Temperature
        • Day 1 Supplement: IR Light Proximity Sensor
      • Day 2: Ultrasound >
        • Day 2 Supplement: IR Temp Sensor
        • Day 2 Supplement: Controlling A Servo
      • Day 3: Measuring Pulse >
        • Day 3 Supplement: Motion Sensor
      • Day 4: OLED Screen Basics >
        • Temperature Screen Display
        • IR Temp Sensor And Screen
      • Day 5 Friday: Finishing up/Show
    • 2020 STEM Camp >
      • Home (2020)
      • The 2020 Teachers
      • PreAcademy prep
      • Day 1 Monday: Basics and Lights >
        • Day 1 Supplement Activity
      • Day 2 Tuesday: Servos >
        • Day 2 (Suppliment Activities)
      • Day 3 Wednesday: Making an ECG/EKG! >
        • Day 3 (Supplement Page)
      • Day 4 Thursday: Controlling Servos with EMG >
        • Day 4 Supplemental Activity
      • Day 5 Friday: Finishing up/Show >
        • Unused lessons/content
    • 2018 Lessons >
      • Day 1: Basic Coding
      • Day 2: Motors
      • Day 3: Build Robot Claw
      • Day 4: Saving Positions
      • Day 5: Presentations
    • 2017 Camp >
      • Day 1 (Monday)
      • Day 2: Multicolor LED and Keypad
      • Day 3: Servo and Keypad
      • Day 4: Multiple Motors/Stepper Motor
      • Day 5: Presentations
    • Pictures archive for lessons (some graphic images)
  • Contact Us!