Arduino Programming

Use the reference to find the answers to the following questions.

Conditionals

Read the page on conditionals and write the code for each statement:

if pin1 is high set pin2 to high

if pin3 is not equal to pin4 set both pins 5 and 6 to high

if a is less than or equal to b set pin 7 to low

 

Serial print and println

floats are numbers with decimal points. How do they print?

Write the code to print x in octal

How do you print a tab?

What's the difference between print and println?

Read and display digital values

// Sets pin 13 to the same value as pin 7, declared as an input.

int ledPin = 13;   // LED connected to digital pin 13
int inPin = 7;     // pushbutton connected to digital pin 7
int val = 0;       // variable to store the read value  
void setup() {
   pinMode(ledPin, OUTPUT);      // sets the digital pin 13 as output
   pinMode(inPin, INPUT);        // sets the digital pin 7 as input
}
void loop() {
   val = digitalRead(inPin);     // read the input pin
   digitalWrite(ledPin, val);    // sets the LED to the button's value 
}
What is the warning about connecting digital outputs?

Read and display an analog value

// Reads the voltage on analogPin and displays it on the Serial screen

int analogPin = 3;   // analog device connected to analog pin 3
int val = 0;         // variable to store the value read  
void setup() {
   Serial.begin(9600);              //  setup serial monitor for output
}
void loop() {
   val = analogRead(analogPin);     // read the input pin
   Serial.println(val);             // display the value 
}

What is the warning about analogRead?

 

Rewrite the program above to display a C on a 7 segment display when the switch is on and a 1 on the 7 segment display when the switch is off.

 

 

 

 

 

 

Rewrite the program above to take in 2 analog inputs on pins 2 and 3.