0% found this document useful (0 votes)
27 views

Pins For The LEDs

This document defines pin constants for connecting LEDs to an Arduino board and controlling their color values. The setup function initializes serial communication and sets the pin modes. The loop continuously reads integer color values from serial, constrains the values, fades the LED pins accordingly, and prints the values. This allows controlling two sets of RGB LEDs by sending hex color values from a serial monitor.

Uploaded by

jere711
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)
27 views

Pins For The LEDs

This document defines pin constants for connecting LEDs to an Arduino board and controlling their color values. The setup function initializes serial communication and sets the pin modes. The loop continuously reads integer color values from serial, constrains the values, fades the LED pins accordingly, and prints the values. This allows controlling two sets of RGB LEDs by sending hex color values from a serial monitor.

Uploaded by

jere711
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/ 2

//pins for the LEDs:

const int redPin = 3;


const int greenPin = 5;
const int bluePin = 6;
const int redPin2 = 9;
const int greenPin2 = 10;
const int bluePin2 = 11;
de!ne "EDP#$ 3
de!ne %"EE$P#$ 5
de!ne &L'EP#$ 6
de!ne ()DE*PEED 5
void setup+, -
// initi.li/e seri.l:
*eri.l0begin+9600,;
// 1.2e the pins outputs:
pin3ode+redPin4 5'6P'6,;
pin3ode+greenPin4 5'6P'6,;
pin3ode+bluePin4 5'6P'6,;
pin3ode+redPin24 5'6P'6,;
pin3ode+greenPin24 5'6P'6,;
pin3ode+bluePin24 5'6P'6,;
*eri.l0print+7)rduino 8ontrol "%& LEDs 9onne8ted 5: + *ent (ro1 )rduinno &o.rd ,7,;
*eri.l0print+;<n;,;
=
void loop+, -
// if there;s .n> seri.l .?.il.ble4 re.d it:
while +*eri.l0.?.il.ble+, @ 0, -

// loo2 for the neAt ?.lid integer in the in8o1ing seri.l stre.1:
int red = *eri.l0p.rse#nt+,;
// do it .g.in:
int green = *eri.l0p.rse#nt+,;
// do it .g.in:
int blue = *eri.l0p.rse#nt+,;
int red2 = *eri.l0p.rse#nt+,;
// do it .g.in:
int green2 = *eri.l0p.rse#nt+,;
// do it .g.in:
int blue2 = *eri.l0p.rse#nt+,;
// loo2 for the neBline0 6h.t;s the end of >our
// senten8e:
if +*eri.l0re.d+, == ;<n;, -

// 8onstr.in the ?.lues to 0 C 255 .nd in?ert
// if >ou;re using . 8o11onC8.thode LED4 Dust use 78onstr.in+8olor4 04 255,;7

// This is for COMMON ANODE
//red = 255 C 8onstr.in+red4 04 255,;
//green = 255 C 8onstr.in+green4 04 255,;
//blue = 255 C 8onstr.in+blue4 04 255,;

red = 8onstr.in+red4 04 255,;
green = 8onstr.in+green4 04 255,;
blue = 8onstr.in+blue4 04 255,;

red2 = 8onstr.in+red24 04 255,;
green2 = 8onstr.in+green24 04 255,;
blue2 = 8onstr.in+blue24 04 255,;
// f.de the red4 green4 .nd blue legs of the LED:
.n.logErite+redPin4 red,;
.n.logErite+greenPin4 green,;
.n.logErite+bluePin4 blue,;

.n.logErite+redPin24 red2,;
.n.logErite+greenPin24 green2,;
.n.logErite+bluePin24 blue2,;
// print the three nu1bers in one string .s heA.de8i1.l:
*eri.l0print+7D.t. "esponse : 7,;
*eri.l0print+red4 FEG,;
*eri.l0print+green4 FEG,;
*eri.l0println+blue4 FEG,;
=
=
=

You might also like