Question

In: Computer Science

•Create a state machine that is sort of like a computer mouse with right clicks and...

Create a state machine that is sort of like a computer mouse with right clicks and left clicks. Instead it uses pB1 and pB2.

Two fast clicks of pB1 turns on led 1 for 5s

Click on pB2 from the idle state you simply turn on LED2 while the button is held in

Below is a state machine I've set up to turn on an LED for 5 s
if a pB is pushed one time, which is only a small part of what i need, i need to make it so it will take a double click instead of a single click and i also need to add a part that turns on a different LED that only turns on when the buttons is pressed, if you can help me complete my code that would be great, thank you  

#include <myGPIO.h>
#include <myTimer.h>


void setup() {

init_gpio_b(4,0); // PB init for input
init_gpio_b(5,0);
  
init_gpio_d(2,1); // Init LED outputs
init_gpio_d(3,1);

// init_TimerInterrupt();
Serial.begin(9600);
}

void loop() {
while(1){
whichCase();
myDelay1ms(5);
}
  
}
void whichCase(void){
static int val=0;
static int state=0;
static int count=0;

Serial.println(PORTD);
switch(state){
  
case 0:{ //****** Idle ****
// *** Do what the state does ****
gpo_d(3,1);
// *** criteria to leave the state ****
if(gpi_b(4)==0)state=1;   
}
break;
  
case 1:{ //****Wait****
// *** Do what the state does ****
  
count++;

// *** criteria to leave the state ****
if(count>100){
state=0;
count=0;
}
else if(gpi_b(4)==1){
state=2;
count=0;
}
  
}
break;
case 2:{ //****ledOn****
// *** Do what the state does ****
  
gpo_d(3,0);
count++;

// *** criteria to leave the state ****
if(count>1000){
state=0;
count=0;

}
  
}
break;


  
default:{
break;
}
}
}

Solutions

Expert Solution

LED configurations with the LE abbreviation in the code

/*
* Mouse clicking panels
*
* configuration for pin B1
* Configuration for pin B2
* Configuration for LE 1
*
* please Mention the name of your project to be displayed in panel
*/

// Assign different pin colours to the System so that you can easily differentiate

int red = 6, yellow = 5, green = 4;

// Different System Variables

byte state = 0; // Mentioning the initial state

void setup() {
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
}

void loop() {

switch(state){
case 0:
digital_Write(red, HIGH);
digital_rite(yellow, LOW);
digital_rite(green, LOW);
delay(1000);
state = 1;
break;


case 1:
digital_rite(red, HIGH);
digital_rite(yellow, HIGH);
digital_rite(green, LOW);
delay(3000);
state = 2;
break;


case 2:
digital_rite(red, LOW);
digital_rite(yellow, LOW); // i have designed different clicking patterns as per your // requirment in the above given question
digital_rite(green, HIGH);
delay(800);
state = 3;
break;

case 3:
digital_rite(red, LOW);
digital_rite(yellow, HIGH);
digital_Write(green,Low);
delay(200);
state = 0;
break;

default:
break;
}
}


Related Solutions

(Not in Swing) Write a JavaFX application that creates polyline shapes dynamically using mouse clicks. Each...
(Not in Swing) Write a JavaFX application that creates polyline shapes dynamically using mouse clicks. Each mouse click adds a new line segment to the current polyline from the previous point to the current mouse position. Allow the user to end the current polyline with the double click. Also, provide a button that clears the window and allows the user to begin again.
In this problem, you will need to create a state machine that stimulates a simple bank...
In this problem, you will need to create a state machine that stimulates a simple bank account in Python 3.6. Any withdrawal when the balance is less than $100 incurs a $5 charge. The state machine should fulfill the following: • The starting balance is specified when instantiating the object. • The output of the state machine is the current balance after the transaction. Sample interaction: >>> acct = SimpleAccount (110) >>> acct . start () >>> acct . step...
Create a Java Application that implements a Selection sort algorithm to sort an array of 20...
Create a Java Application that implements a Selection sort algorithm to sort an array of 20 unsorted numbers. You should initiate this array yourself and first output the array in its original order, then output the array after it has been sorted by the selection sort algorithm. Create a second Java Application that implements an Insertion sort algorithm to sort the same array. Again, output the array in its original order, then output the array after it has been sorted...
Create a Java Application that implements a Selection sort algorithm to sort an array of 20...
Create a Java Application that implements a Selection sort algorithm to sort an array of 20 unsorted numbers. You should initiate this array yourself and first output the array in its original order, then output the array after it has been sorted by the selection sort algorithm.
In C++ Create a program that uses Selection Sort and Insertion Sort for the National Football...
In C++ Create a program that uses Selection Sort and Insertion Sort for the National Football League list of current players. It's going to be a big list(over 1000 names). Please identify, in comments, which part of the code is for the Selection Sort and which part of the code is for Insertion Sort. It must have both. Inputting data from a text file named "Players.txt" Only want the name of the player(first name then last name), their team name,...
Assignment 2: Create a form that collects 5 different pieces of data. Once the user clicks...
Assignment 2: Create a form that collects 5 different pieces of data. Once the user clicks the submit button, the processing PHP file displays the data that was entered thru the form, performs a calculation, and displays the result. To receive full credit, students need to implement the following: Create variables with valid names and assign values to them Use literals and concatenate strings Use $_POST Use echo statements to display data on a page Code string and numeric expressions...
Sam Nolan clicked the mouse for one more round of solitaire on the computer in his...
Sam Nolan clicked the mouse for one more round of solitaire on the computer in his den. He’d been at it for more than an hour, and his wife had long ago given up trying to persuade him to join her for a movie or are Saturday night on the town. The mind-numbering game seemed to be all that calmed Sam down enough to stop thinking about work and how his job seemed to get worse every day. Nolan was...
Texas is a right-to-work state?
Texas is a right-to-work state?
Happy Clicks Inc. uses a predetermined overhead allocation rate of $4.75 per machine hour. Actual overhead...
Happy Clicks Inc. uses a predetermined overhead allocation rate of $4.75 per machine hour. Actual overhead costs incurred during the year are as follows: Indirect materials $5,200 Indirect labor $3,750 Plant depreciation $4,800 Plant utilities and insurance $9,530 Other plant overhead costs $12,700 Total machine hours used during the year 7,520 hours What is the amount of manufacturing overhead cost allocated to Work-in-Process Inventory during the year? Is the manufacturing overhead account under or over allocated and if so by...
(code in C++ language) [Code Bubble sort, Insertion sort Create a Big array with random numbers....
(code in C++ language) [Code Bubble sort, Insertion sort Create a Big array with random numbers. Record the time. Run Bubble Check time (compute the processing time) do it 100 times (random numbers) Take the average Insertion: Compare] (some explanations please)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT