Professional Documents
Culture Documents
THE SETUP
For this you will need switches, LEDs, wires and 330Ω resistors.
3. Open up the Arduino IDE and cut and paste the following code
/*
* PCI Lab
* 1 bit
* Will read the state of one switch on pin 2
* Author:
* Date :
*/
// digital pin 2 has a pushbutton attached to it
int pushButton = 2;
/*
* Lab 3
* Program to read the state of 4 buttons (a half byte) and print out the
* Binary values, decimal and Hex values.
* Author:
* Date :
*/
// We will use the following pins
int pinButton1 = 2;
int pinButton2 = 3;
int pinButton3 = 4;
int pinButton4 = 5;
// Decimal value
int decValue = 0;
Modify the program in part 2 so you implement an 8 bit register. This will
represent a byte of information. I.e. 0 to 255 decimal, 00000000 to 11111111
binary and 00 to FF hex
When you press any combination of the 8 buttons, you should display the
binary value, the decimal value and the hexadecimal value on the serial
monitor. E.g. press 10101010 which is 170 decimal and AA hex.
To do this you will need to:
o Add 4 more LEDs/switches, etc. to the circuit
o Modify the code to handle 8 switches/pins
o Calculate the value of decValue (between 0 and 255)
Upload (cut and paste) your completed code in lab 3 assignment in
Moodle.
Take a picture of your Arduino circuit (similar to Figure 4 ) and upload it
in moodle in topic 3