Hello, I'm going to do a graduation work that sends out a specific output when I adjust the slope to the pattern.
I use the tilt sensor above
For example, if you set the pattern to front, back, left, and right,
Therefore, the instrument must be tilted forward, backward, left and right to emit a specific signal.
I'm using Arduino. What I've done so far is to print the led according to each tilt.
But since then, I haven't really figured out what to do with a pattern, and I'm asking you to give me some advice, because I don't know what to do with it, so I'm asking you for advice"T"
Until now, each LED is turned on according to the direction of inclination.
Additionally, below it'since
int OUTA;
int OUTB;
int Red = A0; // I'm going to turn on the signal to Bluetooth first
int sensor; // I added a new one this time
typedef enum {UP, DOWN, LEFT, RIGHT} direction;
direction sequence[] = {UP, DOWN, LEFT}; // pattern of up-down-left
int position = 0;
void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(Red, OUTPUT);
Serial.begin(9600);
}
void loop() {
OUTA = digitalRead(6);
OUTB = digitalRead(7);
Sensor = 2*OUTA + OUTB; // Express OUTA and OUTB as one value of sensor to compare patterns; is it right to do well?Hah!
if (OUTA == 0 && OUTB == 0) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
if (OUTA == 1 && OUTB == 0) {
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
if (OUTA == 0 && OUTB == 1) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
}
if (OUTA == 1 && OUTB == 1) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
}
Serial.print("Photo 1:"); // outa and outb and made to see how to read the sensor values
Serial.print(digitalRead(6), DEC);
Serial.print(" ; ");
Serial.print("Photo 2: ");
Serial.println(digitalRead(7), DEC);
Serial.print(" ; ");
Serial.print("current_direction: ");
Serial.println(sensor, DEC);
delay(1000);
direction current_direction;
//Save the value of current_direction according to the values of OUTA and OUTB. next time
if (sequence[position] == current_direction) {
position++;
if (position == 3)
{
digitalWrite(Red, LOW);
}
}
else {
int position = 0;
digitalWrite(Red, HIGH);
}
}
For example, if I input front-rear-left-right-left, does it make a sound? You can put a value in the array and check if that value comes out.
For your information, direction is for storing directions, so you can just use int and use 0,1,2,3.
typedef enum {UP, DOWN, LEFT,RIGHT} direction;
direction sequence[]={UP,DOWN,LEFT};//up-down-left pattern
int position=0;
void loop(){
direction current_direction;
//Save the value of current_direction according to the values of OUTA and OUTB. next time
if(sequence[position] == current_direction){
position++;
if(position == 3){
//Success
}
}
else{
//To initialize as soon as an invalid input is received, you can set position=0 here.
//It should be entered as up-down-left, but it depends on whether or not you allow up-down-left.
}
}
567 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
577 PHP ssh2_scp_send fails to send files as intended
573 Understanding How to Configure Google API Key
887 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
600 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.