0% found this document useful (0 votes)
39 views8 pages

Led Pattern Docu

Uploaded by

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

Led Pattern Docu

Uploaded by

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

Rizal Technological University

College of Engineering and Industrial Technology


Boni Avenue, Mandaluyong City

Advance Internet Technologies

ARDUINO
LED PATTERN WITH PUSH BUTTON & POTENTIOMETER

Submitted By:
Borres, Kristine
Marcelo, Irene M.

MH / 4:30 – 7:30 / ITC 104


S.Y. 2019
SCHEMATIC DIAGRAM
SOURCE CODE
int pattern = 0;

void setup() {

Serial.begin(9600);

for (int ledPin = 2; ledPin <= 12; ledPin++) {


pinMode(ledPin, OUTPUT);
}
pinMode(13, INPUT);
}

void loop() {

int potVal = analogRead(A0); //value between 0 and 1023


potVal = map(potVal, 40, 1020, 50, 500);

if (digitalRead(13) == HIGH) {
Serial.println();
Serial.println("Button is pressed");
pattern++;
Serial.print("Button press #");
Serial.println(pattern);
}

switch(pattern) {

case 1:
Serial.println("pattern 1: march is selected");
Serial.print(potVal);
Serial.print(" | ");
Serial.println(analogRead(A2));

march(potVal);
break;

case 2:
Serial.println("pattern 2: negmarch is selected");
Serial.print(potVal);
Serial.print(" | ");
Serial.println(analogRead(A2));

negmarch(potVal);
break;
case 3:
Serial.println("pattern 3: flash is selected");
Serial.print(potVal);
Serial.print(" | ");
Serial.println(analogRead(A2));

flash(potVal);
break;

case 4:
Serial.println("pattern 4: oneAtATime is selected");
Serial.print(potVal);
Serial.print(" | ");
Serial.println(analogRead(A2));

oneAtATime(potVal);
break;

case 5:
Serial.println("pattern 5: alternate is selected");
Serial.print(potVal);
Serial.print(" | ");
Serial.println(analogRead(A2));

alternate(potVal);
break;

case 6:
Serial.println("pattern 6: randomSequence is selected");
Serial.print(potVal);
Serial.print(" | ");
Serial.println(analogRead(A2));

randomSequence(potVal);
break;

case 7:
Serial.println("pattern 7: fillall - change color");
Serial.print(potVal);
Serial.print(" | ");
Serial.println(analogRead(A2));

fillall();
delay(1000);
break;

default:
clearall();
pattern = 0;

Serial.println("----- TURN OFF -----");


delay(1000);
break;
}
}

void clearall() { // sets all OUTPUT pin to LOW

for (int ledPin = 2; ledPin <= 12; ledPin++) {


digitalWrite(ledPin, LOW);
}
}

void fillall() { // sets all OUTPUT pin to HIGH

for (int ledPin = 2; ledPin <= 12; ledPin++) {


digitalWrite(ledPin, HIGH);
}
}

/* Marches a LED back and forth across a lit LED line array */
void march(int delaytime) {

int right_ledPin = 9;
int right_ledPin_Minus = 12;

for (int left_ledPin = 2; left_ledPin <= 7; left_ledPin++) {


if (left_ledPin == 4) continue;

clearall();
digitalWrite(left_ledPin, HIGH);

if (left_ledPin >= 3) {
digitalWrite(right_ledPin, HIGH);
right_ledPin++;
}

delay(delaytime);
}

for (int left_ledPin = 7; left_ledPin >= 2; left_ledPin--) {


if (left_ledPin == 4) continue;
clearall();
digitalWrite(left_ledPin, HIGH);
digitalWrite(right_ledPin_Minus, HIGH);

delay(delaytime);

right_ledPin_Minus--;
}
}

/* Same as march, but instead an unlit LED marches


* across a lit LED line array
*/
void negmarch(int delaytime) {

int right_ledPin = 9;
int right_ledPin_Minus = 12;

for (int left_ledPin = 2; left_ledPin <= 7; left_ledPin++) {


if (left_ledPin == 4) continue;

fillall();
digitalWrite(left_ledPin, LOW);

if (left_ledPin >= 3) {
digitalWrite(right_ledPin, LOW);

right_ledPin++;
}
delay(delaytime);
}

for (int left_ledPin = 7; left_ledPin >= 2; left_ledPin--) {


if (left_ledPin == 4) continue;

fillall();
digitalWrite(left_ledPin, LOW);
digitalWrite(right_ledPin_Minus, LOW);
delay(delaytime);
right_ledPin_Minus--;
}
}

/* This alternates between all lit and all off, used to show
* reading across the analog ports
*/
void flash(int delaytime) {

clearall();
delay(delaytime);

fillall();
delay(delaytime);
}

/* Utterly twinking random */


void randomSequence(int delaytime) {

clearall();

for (int n = 0; n < 5; n++) {

RandomA:
int randomLed = random(2, 11);

if (randomLed == 4 || randomLed == 8) goto RandomA;

digitalWrite(randomLed, HIGH);
delay(delaytime);

RandomB:
randomLed = random(2, 11);
if (randomLed == 4 || randomLed == 8) goto RandomB;

digitalWrite(randomLed, LOW);
}
}

/* Turns each LED off one at a time */


void oneAtATime(int delaytime) {

clearall();

for (int ledPin = 2; ledPin <= 7; ledPin++) {


if (ledPin == 4) continue;

digitalWrite(ledPin, HIGH);
delay(delaytime);
digitalWrite(ledPin, LOW);
}

for (int ledPin = 11; ledPin >= 9; ledPin--) {


digitalWrite(ledPin, HIGH);
delay(delaytime);
digitalWrite(ledPin, LOW);
}
}

/* This is the same as the flash function, but every other LED
* either turns on or off alternately
*/
void alternate(int delaytime) {

int right_ledPin = 9;
clearall();

for (int ledPin = 2; ledPin <= 7; ledPin += 2) {


if (ledPin == 4) ++ledPin;

if (ledPin == 2 || ledPin == 5 || ledPin == 7) {


digitalWrite(ledPin, HIGH);
digitalWrite(10, HIGH);
}
}
delay(delaytime);
clearall();

for (int pin = 3; pin <= 6; pin += 3) {


digitalWrite(pin, HIGH);
digitalWrite(right_ledPin, HIGH);
right_ledPin += 2;
}
delay(delaytime);
}

You might also like