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 the code and combination match the program will go to the Unlocked mode and start flashing the LED. A long press of the button will engage the lock again. Throughout this discussion it is assumed that there will be three integer arrays, each with 4 elements, declared as globals. One named Combination is the combination for our lock. Another will be called Code and is the code the user enters to try and unlock the lock. Finally an array named SerialInput, which is used to buffer data from the serial port, which will be transferred to Combination, once a four valid number are received
we will produce code that will read data in from the serial port and collect the input into SerialInput, and once we have 4 digits we will copy them over to the combination and write them to EEPROM. Then each time the system is reset (setup is run), we will want to read Combination from EEPROM and print it to the serial port. The code for this should go in loop and the pseudo code for this is included here:
If serial data is available
Read in current character
If character is a digit, greater than or equal to ‘0’ and less than or equal to ‘9’
Convert to a number and place in SerialInput
If four digits have come in Copy SerialInput to Combination
and write to EEPROM
end
else // not a digit
reset buffer to wait for four new digits end end
Similarly in setup code should be added
Read four integers from the EEPROM placing them in Combination.
if any of the numbers in Combination are not > 0 and < 9
Reset Combination to a simple default, such as 1,2,3,4
And write to EEPROM
ButtonDebounce Header File:
#ifndef ButtonDebounce_h
#define ButtonDebounce_h
#include "Arduino.h"
enum ButtonState{ButtonIdle, ButtonWait, ButtonHigh} state;
unsigned long ButtonTime;
int ButtonInitialize() {
pinMode(4, INPUT);
pinMode(13, OUTPUT);
}
int ButtonNextState(int Input) {
switch (state) {
case ButtonIdle:
if (Input == LOW) {
ButtonTime = millis();
state = ButtonWait;
digitalWrite(13, HIGH);
}
break;
case ButtonWait:
if (Input == HIGH) {
state = ButtonIdle;
}
else if (millis() - ButtonTime >= 5) {
state = ButtonHigh;
digitalWrite(13, LOW);
return 1;
}
break;
case ButtonHigh:
if (Input == HIGH) {
state = ButtonIdle;
return 2;
}
break;
}
return 0;
}
#endif
#ifndef ButtonDebounce_h
#define ButtonDebounce_h
#include "Arduino.h"
enum ButtonState{ButtonIdle, ButtonWait, ButtonHigh} state;
unsigned long ButtonTime;
void setup() {
int ButtonInitialize() {
pinMode(4, INPUT);
pinMode(13, OUTPUT);
}}
void loop ()
{
int ButtonNextState(int Input) {
switch (state) {
case ButtonIdle:
if (Input == LOW) {
ButtonTime = millis();
state = ButtonWait;
digitalWrite(13, HIGH);
}
break;
case ButtonWait:
if (Input == HIGH) {
state = ButtonIdle;
}
else if (millis() - ButtonTime >= 5) {
state = ButtonHigh;
digitalWrite(13, LOW);
return 1;
}
break;
case ButtonHigh:
if (Input == HIGH) {
state = ButtonIdle;
return 2;
}
break;
}
return 0;
}
#endif
}
Hello I need help with the following I'm having trouble getting to just the main code....
Need help in filling the missing lines in the program template provided down below. (Arduino Uno). Using the program template provided, fill in the missing lines in the program which increments an unsigned integer variable when the “pin 2” button is pressed and decrements an unsigned integer variable when the “pin 3” button is pressed. Your program must display the integer variable (modulo 8) on the 7-segment LED display you designed in the previous lab. Once again you should be...
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 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 =...
This question is about the Arduino code.
Please complete a 4-input circuit on your Arduino. Your circuit,
in addition to cycling through a binary representation of the
numbers 0-15 using LEDs, should use the Serial port to output the
decimal equivalent of each of the numbers in the format:
Output: 15
... if the value was 1111, and so forth.
You will be asked to upload your code as well as a photo of your
working breadboard circuit.
Add comments...
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...
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...
Hello, I am having trouble with this C++ programming assignment. If someone could write the code or at least part of it that would help me, because every code I try has errors. Using if Statements, Loops and Nested Loops • Scanning Characters in a String Using a Loop • Performing Character Arithmetic In project, you will write an interactive program that, counts the number of digits in a non-negative integer, factorizes the integer into powers of ten and its...
c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...
C++: Need help debugging my code
I am writing this and using some other examples as reference code
while rewriting it with my own understanding of the material but am
having trouble making it finally compile. Below is a picture of the
error messages.
//main.cpp
//Semester Project
//Created by J---on 5/6/2019
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
void instructions(); //displays program details and
instructions
void openFile();
void takeInput(int*);
void switchBoard(int*);
struct price
{...
I am having trouble understanding how this code is able to use the contents of the header file. Can someone please provide comments in the main code to describe what is happening? (especially on the bool isNumber) THE MAIN CODE: #include<bits/stdc++.h> #include "MyCartesianPoint.h" #include <math.h> #include <iostream> using namespace std; bool isNumber(string s) { if(!isdigit (s[0])) { if(s[0] != '-') return false; else if(s.length() == 1) return false;...