Need help in filling the missing lines in the program template provided down below. (Arduino Uno).
Program Template:
// Breadboard using the same pins as used in the code…
int incrButtonPin = 6; // Increment Button Pin
int decrButtonPin = 5; // Decrement Button Pin
int counter = 0; //Keeps track of the current digital value
boolean IncButtonLast = LOW;
boolean IncButtonCurrent = LOW;
boolean DecButtonLast = LOW;
boolean DecButtonCurrent = LOW;
void setup() { // Increment and decrement pins
pinMode(incrButtonPin, INPUT);
pinMode(decrButtonPin, INPUT); // pins used for 7-segment Display
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
// pins used for input to the DAC R2R Ladder
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
}
void LEDDisplay(int count)
{ switch(count) // Each case value also corresponds to the decimal value. Ex) Case 0 is decimal 0 and so on.
{ case 0: digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
break;
case 1: digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
break; //Fill in the missing cases here..
default:
// Display letter 'd'..
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
}//switch-case
}//function
void DACInput(int counter2)
{ //This function sets the three pins connected to the R2R ladder input and makes them LOW/HIGH // depending on the current digital(decimal) value displayed on the LED by converting them into // binary (LOW/HIGH) for each pin. //This is nothing related to the LED so no reverse logic is used.
switch(counter2)
{ case 0: // 000 = 0
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
break;
case 1: // 001 = 1
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
break;
case 2: // 010 = 2
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
break;
case 3: // 011 = 3
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
break;
// Fill in the missing cases..
default: // All low
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}//switch-case
}//DACInput function
boolean waitForINCRButtonPush(boolean lastIncrSwitchState)
{
boolean currentIncrSwitchState = digitalRead(incrButtonPin);
if(lastIncrSwitchState != currentIncrSwitchState) delay(20);
currentIncrSwitchState = digitalRead(incrButtonPin);
return currentIncrSwitchState;
}
boolean waitForDECRButtonPush(boolean lastDecrSwitchState)
{ //This function waits for a button push and also debounces it..
boolean currentDecrSwitchState = digitalRead(decrButtonPin);
if(lastDecrSwitchState != currentDecrSwitchState) delay(20);
currentDecrSwitchState = digitalRead(decrButtonPin);
return currentDecrSwitchState;
}
void loop()
{
//This is waiting for the increment button push and also debounces it..
IncButtonCurrent = waitForINCRButtonPush(IncButtonLast);
if(IncButtonLast == LOW && IncButtonCurrent == HIGH)
{ counter++; //Advancing count by 1 since increment button was pushed.
}
////This is waiting for the decrement button push and also debounces it..
DecButtonCurrent = waitForDECRButtonPush(DecButtonLast);
if(DecButtonLast == LOW && DecButtonCurrent == HIGH)
{ ; //Fill in the missing line: Hint: Decrement what?
if(counter<0)
;//Fill in missing line: Hint: Ensures wrap around back to 7 if decrement occurs at 0
} //Modulo 8 will ensure our values don’t exceed 7 and wrap-around
counter = ; // Fill in missing parts here: Hint: Perform a modulo 8 operation.
//Display values on the 7-segment LED
LEDDisplay(Fill in missing part);
//Set the binary value for each of the three pins connected to the R2R Ladder(DAC).
DACInput(Fill in missing part);
//Current states become the previous states for the next automatic call to the loop()
IncButtonLast = IncButtonCurrent;
DecButtonLast = DecButtonCurrent;
}//loop()
// Breadboard using the same pins as used in the code…
int incrButtonPin = 6; // Increment Button Pin
int decrButtonPin = 5; // Decrement Button Pin
int counter = 0; //Keeps track of the current digital value
boolean IncButtonLast = LOW;
boolean IncButtonCurrent = LOW;
boolean DecButtonLast = LOW;
boolean DecButtonCurrent = LOW;
void setup() { // Increment and decrement pins
pinMode(incrButtonPin, INPUT);
pinMode(decrButtonPin, INPUT); // pins used for 7-segment Display
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
// pins used for input to the DAC R2R Ladder
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
}
void LEDDisplay(int count)
{ switch(count) // Each case value also corresponds to the decimal value. Ex) Case 0 is decimal 0 and so on.
{ case 0: digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
break;
case 1: digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
break; //Fill in the missing cases here..
case 2: digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
break;
case 3: digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
break;
case 4: digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
break;
case 5: digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
break;
case 6: digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
break;
case 7: digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
break;
//it use modulo 8 arithmetic so no need for case 8 and case 9
default:
// Display letter 'd'..
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
}//switch-case
}//function
void DACInput(int counter2)
{ //This function sets the three pins connected to the R2R ladder input and makes them LOW/HIGH // depending on the current digital(decimal) value displayed on the LED by converting them into // binary (LOW/HIGH) for each pin. //This is nothing related to the LED so no reverse logic is used.
switch(counter2)
{ case 0: // 000 = 0
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
break;
case 1: // 001 = 1
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
break;
case 2: // 010 = 2
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
break;
case 3: // 011 = 3
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
break;
// Fill in the missing cases..
case 4: // 100 = 4
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
break;
case 5: // 101 = 5
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
break;
case 6: // 110 = 6
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
break;
case 7: // 111 = 7
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
break;
default: // All low
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}//switch-case
}//DACInput function
boolean waitForINCRButtonPush(boolean lastIncrSwitchState)
{
boolean currentIncrSwitchState = digitalRead(incrButtonPin);
if(lastIncrSwitchState != currentIncrSwitchState) delay(20);
currentIncrSwitchState = digitalRead(incrButtonPin);
return currentIncrSwitchState;
}
boolean waitForDECRButtonPush(boolean lastDecrSwitchState)
{ //This function waits for a button push and also debounces it..
boolean currentDecrSwitchState = digitalRead(decrButtonPin);
if(lastDecrSwitchState != currentDecrSwitchState) delay(20);
currentDecrSwitchState = digitalRead(decrButtonPin);
return currentDecrSwitchState;
}
void loop()
{
//This is waiting for the increment button push and also debounces it..
IncButtonCurrent = waitForINCRButtonPush(IncButtonLast);
if(IncButtonLast == LOW && IncButtonCurrent == HIGH)
{ counter++; //Advancing count by 1 since increment button was pushed.
}
////This is waiting for the decrement button push and also debounces it..
DecButtonCurrent = waitForDECRButtonPush(DecButtonLast);
if(DecButtonLast == LOW && DecButtonCurrent == HIGH)
{counter-- ; //Fill in the missing line: Hint: Decrement what?
if(counter<0)
counter=7;//Fill in missing line: Hint: Ensures wrap around back to 7 if decrement occurs at 0
} //Modulo 8 will ensure our values don’t exceed 7 and wrap-around
counter =counter % 8 ; // Fill in missing parts here: Hint: Perform a modulo 8 operation.
//Display values on the 7-segment LED
LEDDisplay(counter);
//Set the binary value for each of the three pins connected to the R2R Ladder(DAC).
DACInput(counter);
//Current states become the previous states for the next automatic call to the loop()
IncButtonLast = IncButtonCurrent;
DecButtonLast = DecButtonCurrent;
}//loop()
Need help in filling the missing lines in the program template provided down below. (Arduino Uno)....
Using the template provided in the lab details section, formulate a
program for the Arduino to generate a PWM signal duty cycles
between 0% and 100% at intervals of 10% where a button will
increment the PWM signal. Remember the RC is 10 milliseconds.
Provide a copy of the final code and explain how it works.
Arduino PWM Example int Pin = 9; void setup() { pinMode (Pin, OUTPUT); } void loop() { analogWrite (Pin, 127); // Generate 50% duty...
Program is for an Arduino 1. Add the letters “A”, “b”, “c”, “d”, “E”, “F” to your homework program. Continually display “0123”, “4567”, “89Ab”, “cdEF” with a one second delay between each one. HINT: Expand pickNumber() to use numbers 10-15 (a-f in hex). Create new functions for a-f. (THIS IS THE CODE FROM THE HOMEWORK) /*************************************** name:Stopwatch function: you can see the number increases by one per second on the 4-digit 7-segment display. ***********************************/ //Email:support@sunfounder.com //Website:www.sunfounder.com /**************************************/ #include //the pins...
I have a program for Arduino written such that when I hold a
button down, it will turn an LED off. I want to be able to print to
the serial monitor how long the button was pressed for after I let
go of the button. Does anybody have any ideas? Below is the code I
have written thus far:
Text of Code:
#define LED RED_LED
#define buttonPIN PUSH2
const int buttonPin = PUSH2; // the number of the pushbutton...
I'm trying to make a circuit from this code that I found for a personal project, but I'm having trouble figuring it out. Could someone make me a Circuit Diagram for this code with an LED, Servo, and Arduino Nano on BreadBoard. (No Battery, just use usb power from Nano) Thank You. Nano Code: const int servoPin = 5; const int buttonPin = 3; const int LEDPin = 4; #include <Servo.h> Servo visorServo; void setup() { visorServo.write(0); // Initial position...
I am doing an Arduino Uno project where I made a "Simon says" memory game with 3 neopixel LED strips and 3 - ultrasonics. I have them working independently but I need to combine the code so they work together. Here is what I have: Memory Game #define PLAYER_WAIT_TIME 2000 // The time allowed between button presses - 2s byte sequence[100]; // Storage for the light sequence byte curLen = 0; // Current length of the sequence byte inputCount =...
Please explain to me how the following arduino code control the
smart home system design below.
#include "ESP8266.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <dht.h>
#define DATA_PIN 2
#define SSID "abc"
#define PASSWORD "12345678"
byte termometerLogo[8] =
{
B00100,
B01010,
B01010,
B01110,
B01110,
B11111,
B11111,
B01110
};
byte humidityLogo[8] =
{
B00100,
B00100,
B01010,
B01010,
B10001,
B10001,
B10001,
B01110,
};
SoftwareSerial mySerial(10,11);
ESP8266 wifi(mySerial);
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3,
POSITIVE);
dht DHT;
char buffData[150];
const int...
In the code below i am using a LS-3006 SERVO on the arduino uno and everytime i hit the pushbutton to input a time the servo comes on. Would anyone be able to tell me what a solution is to this problem? Thanks #include <Wire.h> #include <DS3231.h> #include <Servo.h> #include <LiquidCrystal.h> #include <Keypad.h> const byte ROWS = 4; // # of rows const byte COLS = 4; // # of columns // Define the Keymap char keys[ROWS][COLS] = { {'1','2','3','A'},...
ARM assembly using breadboard Ladder Game - This game involves a setup of LEDs in a row and a button. The goal is to get from the bottom led all the way to the top without them resetting. The LEDs will flash and you can only move up one led at a time, when the led is lit up, or else you get reset to the bottom. code in C please convert to ARM assembly #include <stdio.h> #include <stdlib.h> #include...
Hello I need help with the following I'm having trouble getting to just the main code. Attached is the ButtonDebounce header file and the description of the code the language is C++; This lab will end with a functioning combination lock. The lock will have a combination that resides in EEPROM, and is programmable via the serial port. The user will enter a code, using the button and encoder on the board, and is shown on the lcd screen. Once...
I need help with doing these tasks for code
composer
Lab 3 - Branching, Push Button and LEDs-Reading Assignment in this lab, we are going to control a LED via a push button- using general purpose digital 10 for both input (button) and output (LED) on port 1 - using Code Composer Studio. Furthermore, we are going to use a branch instruction to create an IF-ELSE structure in assembly to determine if the LED should be lit up based on...