Question

In: Electrical Engineering

With an Arduino Uno: Using 2 external buttons b0 and b1 to represent ‘0’ and ‘1’,...

With an Arduino Uno:

Using 2 external buttons b0 and b1 to represent ‘0’ and ‘1’, design a sequence detector to detect a pattern “1101”. An LED lights up once, when the sequence “1101” occurs.

Solutions

Expert Solution


// A flag variable is used to verify the sequence is correct. flag is incremented at each correct input.
int flag = 0;

int check(int x,int y)
{
switch(flag)
{
    case 0 : {
              if(y==1 && x==1) //evaluates true when b1 is pressed
              {
                flag =1;        // 1 detected
              }
              else flag = 0;
              break;
    }
    case 1 : {
              if(y==1 && x==1) //evaluates true when b1 is pressed
              {
                flag = 2;       // 1 detected
              }
              else flag = 0;    // 0 detected
              break;
    }
    case 2 : {
               if(y==0 && x==0) //evaluates true when b0 is pressed
               {
                flag = 3;       // 0 detected
               }
               else if(y==1 && x==1) //evaluates true when b1 is pressed
               {
                flag = 2;       // 1 detected, Now sequence is '111....' Hence flag =2;
               }
               else ;
               break;
    }
    case 3 : {
              if(y==1 && x==1) //evaluates true when b1 is pressed
              {
                flag = 4;       // 1 detected
              }
              if(y==0 && x==0) //evaluates true when b0 is pressed
              {
                flag = 0;       // 0 detected
              }
              break;
    }
}
if(flag==4)
{
digitalWrite(3,HIGH);         // LED set to high
delay(2000);
digitalWrite(3,LOW);         // LED set to low
flag=2;                       //'1101' detected. If las one has to be taken as 1st input of following sequnece keep it. Else if you want to start fresh, change value of flag to 0.
}

return 0;
}


void setup() {

//let the inputs be connected at pin 0,1
//note that PIN0 represents b0 which signifies '0' and hence should be pulled up using a resistor to +5V. This is necessary to identify a change from high level(5V) to low level(0).
//note that PIN1 represents b1 which signifies '1' and hence should be pulled down using a resistor to ground. This is necessary to identify a change from low level(0V) to high level(5V).
pinMode(0,INPUT);
pinMode(1,INPUT);

//let the LED be connected to pin 3
pinMode(3,OUTPUT);

}

void loop() {
//receive inputs and check whether the sequence is 1101

int x = digitalRead(0); //evaluates 0 when b0 is pressed and 1 when not pressed
delay(500);              // avoid debouncing
int y = digitalRead(1); //evaluates 1 when b1 is pressed and 0 when not pressed
delay(500);              // avoid debouncing

check(x,y);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

PROGRAM ENDES ABOVE LINE. BELOW IS THE HARDWARE IMPLEMENTATION ONLINE.



Related Solutions

With a PSoC4 in PSoC creator: Using 2 external buttons b0 and b1 to represent ‘0’...
With a PSoC4 in PSoC creator: Using 2 external buttons b0 and b1 to represent ‘0’ and ‘1’, design a sequence detector using C code in PSoC Creator to detect a pattern “1101”. The board LED lights up once, when the sequence “1101” occurs. Use a serial terminal (UART component and serial terminal emulator application) to display the sequence entered. Use the board button for the sequence detector reset.
Solve the recurrence relation with the given initial conditions. b0 = 0, b1 = 4, bn...
Solve the recurrence relation with the given initial conditions. b0 = 0, b1 = 4, bn = 2bn ? 1 + 2bn ? 2 for n ? 2
this is code to Temperature and Humidity Monitoring over ThingSpeak using Arduino UNO and ESP8266 i...
this is code to Temperature and Humidity Monitoring over ThingSpeak using Arduino UNO and ESP8266 i need someone explain the steps for me #include <stdlib.h> #include <DHT.h> #define DHTPIN 5         // DHT data pin connected to Arduino pin 5 #define DHTTYPE DHT11     // DHT11 (DHT Sensor Type ) DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT sensor #define SSID "WiFi Name"     // "WiFi Name" #define PASS "WiFi Password"       // "Password" #define IP "184.106.153.149"// thingspeak.com ip String msg = "GET /update?key=Your API...
I need simulation on protues of speed control of unipolar stepper motor using uno arduino. Must...
I need simulation on protues of speed control of unipolar stepper motor using uno arduino. Must using protues..
b1 b2 b3 b4 b5 b6 a1 4 2 0 2 1 1 a2 4 3...
b1 b2 b3 b4 b5 b6 a1 4 2 0 2 1 1 a2 4 3 1 3 2 2 a3 4 3 7 -5 1 2 a4 4 3 4 -1 2 2 a5 4 3 2 -2 2 2 Find the optimal strategies and the value of the following game:
0. 0. 0. 0.0. 0. 0. 0. 0. 1. 1. 1. 1. 1. 1. 2. 2. 2. 3. 4.
0. 0. 0. 0.0. 0. 0. 0. 0.   1. 1. 1. 1. 1. 1. 2. 2. 2. 3.   4. A.)MEAN – B.)MEDIAN - C.)MODE - D.)STANDARD DEVIATION – E.)5 NUMBER SUMMARY – F.)BOX AND WHISKERS PLOT – G.) OUTLIERS-
0. 0. 0. 0.0. 0. 0. 0. 0. 1. 1. 1. 1. 1. 1. 2. 2. 2. 3. 4.
0. 0. 0. 0.0. 0. 0. 0. 0.   1. 1. 1. 1. 1. 1. 2. 2. 2. 3.   4. A.)5 NUMBER SUMMARY – B.)BOX AND WHISKERS PLOT – C.) OUTLIERS-
Let A =   [  0 2 0 1 0 2 0 1 0 ]  . (a)...
Let A =   [  0 2 0 1 0 2 0 1 0 ]  . (a) Find the eigenvalues of A and bases of the corresponding eigenspaces. (b) Which of the eigenspaces is a line through the origin? Write down two vectors parallel to this line. (c) Find a plane W ⊂ R 3 such that for any w ∈ W one has Aw ∈ W , or explain why such a plain does not exist. (d) Write down explicitly...
1-Define UDP? 2-What voltage levels are used in RS232 to represent logic 0 and 1
1-Define UDP? 2-What voltage levels are used in RS232 to represent logic 0 and 1
Solve the following ODE using Laplace Transforms ?̈+?̇+3?=0;?(0)=1; ?̇(0)=2
Solve the following ODE using Laplace Transforms ?̈+?̇+3?=0;?(0)=1; ?̇(0)=2
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT