Martha MigliacioAlex Wong
Published © GPL3+

Using the Pmod SWT and Pmod LED with Arduino Uno

Display the states of Pmod SWT slide switches on the Pmod LED while also displaying the decimal number representation on the serial monitor.

BeginnerProtip1 hour832
Using the Pmod SWT and Pmod LED with Arduino Uno

Things used in this project

Story

Read more

Schematics

Pmod SWT, Pmod LED, and Arduino Uno Fritzing file

Fritzing file displaying the connection of the Pmod SWT and Pmod LED to the Arduino Uno.

Pmod SWT, Pmod LED, and Arduino Uno Fritzing Image

Fritzing image displaying the connection between the Pmod SWT, Pmod LED, and Arduino Uno.

Code

Pmod SWT, Pmod LED, and Arduino Uno Code

Arduino
Using this code will show the state of the Pmod SWT slide switches on the Pmod LED and their decimal number representation in the Arduino Uno serial monitor.
/************************************************************************
*
* Test of the Pmod module
*
*************************************************************************
* Description: Pmod_SWT
* The states of switch button will be shown on the LED module
* and their decimal number representation will be also shown on serial monitor
*
* Material
* 1. Arduino Uno
* 2. Module Pmod LED
* 3. Module Pmod SWT
*
************************************************************************/
// Affectation of pins
#define LED_0 2
#define LED_1 3
#define LED_2 4
#define LED_3 5
#define SWT_1 6
#define SWT_2 7
#define SWT_3 8
#define SWT_4 9

boolean inter_1;
boolean inter_2;
boolean inter_3;
boolean inter_4;
int nombre;

void setup()
{
 Serial.begin(9600); // initialization of the serial monitor
 for (int i=2; i<=5; i++) // configuration of pins 2 to 5 in input
 {
  pinMode(i,OUTPUT);
 }
 for (int i=6; i<=9; i++) // configuration of pins 6 to 9 in input
 {
  pinMode(i,INPUT);
 }

}
void loop()
{
 inter_1=digitalRead(SWT_1); // reading SW1
 digitalWrite(LED_0,inter_1); // activate LED0 depending of sw1 state
 inter_2=digitalRead(SWT_2);
 digitalWrite(LED_1,inter_2);
 inter_3=digitalRead(SWT_3);
 digitalWrite(LED_2,inter_3);
 inter_4=digitalRead(SWT_4);
 digitalWrite(LED_3,inter_4);
 nombre=inter_1+inter_2*2+inter_3*4+inter_4*8; // binaire-décimal conversion
 Serial.print("Le nombre decimal est egal à "); // Show in serial monitor
 Serial.println(nombre);
}

Credits

Martha Migliacio

Martha Migliacio

5 projects • 18 followers
Alex Wong

Alex Wong

14 projects • 53 followers
I work in Digilent and like creating projects
Thanks to Lextronics.

Comments