0% found this document useful (0 votes)
24 views11 pages

Robotics Code Collectionfromyourstruly

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views11 pages

Robotics Code Collectionfromyourstruly

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Created for

ROBOTICS
CODE COLLECTION
The Lord is my shepherd,
I shall not want.
He makes me lie down
in green pastures;
He leads me beside still waters.
He restores my soul;
He leads me in the paths of
righteousness
for His name’s sake.
Even though I walk through the
valley of
the shadow of death
I will fear no evil,
for you are with me;
Your rod and your staff,
they comfort me.
You prepare a table before me
in the presence of my enemies.
You anoint my head with oil;
my cup runs over.
Surely your goodness and mercy
will follow me
all the days of my life,
and I will dwell in the house of
the Lord forever.

PSALMS 23:1-6
SWITCH w/ LED
const int buttonPin = 7;
const int ledPin = 8;

int buttonState = 0;

void setup()
{
pinMode(ledPin, OUTPUT);

pinMode(buttonPin, INPUT_PULLUP);
}

void loop()
{
buttonState = digitalRead(buttonPin);

if (buttonState == HIGH)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}

}
SWITCH w/ 5 LEDs
const int buttonPin = 7;
const int ledPin1 = 13;
const int ledPin2 = 12;
const int ledPin3 = 11;
const int ledPin4 = 10;
const int ledPin5 = 9;

int buttonState = 0;

void setup()
{
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);

pinMode(buttonPin, INPUT_PULLUP);
}

void loop()
{
buttonState = digitalRead(buttonPin);

if (buttonState == HIGH)
{
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
digitalWrite(ledPin5, HIGH);
}

else
{
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
}

}
POTENTIOMETER READING
#define POTENTIOMETER_PIN A0

void setup()
{
Serial.begin(9600);
}

void loop()
{
Serial.println(analogRead(POTENTIOMETER
_PIN));
delay(100);
}

POTENTIOMETER W/ LED
const int analog_ip = A0;
const int LED = 13;
int inputVal = 0;

void setup() {
pinMode(LED, OUTPUT);
}

void loop() {
inputVal = analogRead(analog_ip);
analogWrite(LED, inputVal/4);
delay(100);
}
TRAFFIC LIGHTS W/ POTENTIOMETER
int iGREEN = 13;
int iYELLOW = 12;
int iRED = 11;

int potValue = 0;

void setup()
{
pinMode(A0, INPUT);
pinMode(iGREEN, OUTPUT);
pinMode(iYELLOW, OUTPUT);
pinMode(iRED, OUTPUT);
}

void loop()
{
potValue = analogRead(A0);
if (potValue < 341) {
digitalWrite(iGREEN, HIGH);
digitalWrite(iYELLOW, LOW);
digitalWrite(iRED, LOW);
}
if (potValue >= 341 && potValue < 682) {
digitalWrite(iGREEN, LOW);
digitalWrite(iYELLOW, HIGH);
digitalWrite(iRED, LOW);
}
if (potValue >= 682) {
digitalWrite(iGREEN, LOW);
digitalWrite(iYELLOW, LOW);
digitalWrite(iRED, HIGH);
}
delay(10); // Wait for 10 millisecond(s)
}
PHOTOSENSOR READING
int photocellPin = 2;
int photocellReading;
void setup(void)
{
Serial.begin(9600);
}
void loop(void)
{
photocellReading =
analogRead(photocellPin);
Serial.print("Analog reading = ");
Serial.println(photocellReading);
delay(1000);
}

PHOTOSENSOR W/ LED
int photocellPin = 0;
int LED = 2;
int photocellReading;
const float limit = 100;
void setup(void)
{
Serial.begin(9600);
pinMode(LED, OUTPUT);
}
void loop(void)
{
photocellReading = analogRead(photocellPin);
Serial.print("Analog reading = ");
Serial.println(photocellReading);
if (photocellReading < limit)
{
digitalWrite(LED, HIGH);
}
else
{
digitalWrite(LED, LOW);
}
delay(1000);
}
RUNNING LIGHTS (BACK AND FORTH)
int pin9 = 9, pin10 = 10, pin11 = 11, pin12 = 12;

void setup()
{
pinMode(pin9, OUTPUT);
pinMode(pin10, OUTPUT);
pinMode(pin11, OUTPUT);
pinMode(pin12, OUTPUT);
}

void loop()
}
digitalWrite(pin9, HIGH);
delay(1000);
digitalWrite(pin9, LOW);
delay(1000);
digitalWrite(pin10, HIGH);
delay(1000);
digitalWrite(pin10, LOW);
delay(1000);
digitalWrite(pin11, HIGH);
delay(1000);
digitalWrite(pin11, LOW);
delay(1000);
digitalWrite(pin12, HIGH);
delay(1000);
digitalWrite(pin12, LOW);
delay(1000);
digitalWrite(pin11, HIGH);
delay(1000);
digitalWrite(pin11, LOW);
delay(1000);
digitalWrite(pin10, HIGH);
delay(1000);
digitalWrite(pin10, LOW);
delay(1000);
digitalWrite(pin9, HIGH);
delay(1000);
digitalWrite(pin9, LOW);
delay(1000);
}
TRAFFIC LIGHTS W/ 30s DELAY
int iGREEN = 2;
int iYELLOW = 3;
int iRED = 4;
int DELAY_iGREEN = 5000;
int DELAY_iYELLOW = 2000;
int DELAY_iRED = 5000;

void setup()
{
pinMode(iGREEN, OUTPUT);
pinMode(iYELLOW, OUTPUT);
pinMode(iRED, OUTPUT);
}

void loop()
}
green_light();
delay(DELAY_iGREEN);
yellow_light();
delay(DELAY_iYELLOW);
red_light();
delay(DELAY_iRED);
}

void green_light()
{
digitalWrite(iGREEN, HIGH);
digitalWrite(iYELLOW, LOW);
digitalWrite(iRED, LOW);
}

void yellow_light()
{
digitalWrite(iGREEN, LOW);
digitalWrite(iYELLOW, HIGH);
digitalWrite(iRED, LOW);
}

void red_light()
{
digitalWrite(iGREEN, LOW);
digitalWrite(iYELLOW, LOW);
digitalWrite(iRED, HIGH);
}
ULTRASONIC SENSOR
int inches = 0;
int cm = 0;

long readUltrasonicDistance(int triggerPin, int echoPin)


{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
//sets the trigger pin to HIGH state
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in milliseconds
return pulseIn(echoPin, HIGH);
}

void setup()
{
Serial.begin99600);
}

void loop()
}
measure the ping time in cm
cm = 0.01723 * readUltrasonicDistance(7,7);
//convert to inches by dividing by 2.54
inches = (cm / 2.54);
Serial.print(inches);
Serial.print("in");
Serial.print(cm);
Serial.print("cm");
delay(100); //Wait for 100 millisecond(s)
}
あたしが知っている君が一番学生から!^^
君なら出来るよ~ (⁠•⁠ө⁠•⁠)⁠♡

-Georgia Milan W. Garcia


11 - Einstein

You might also like