Can I ask you about the Arduino code?

Asked 2 years ago, Updated 2 years ago, 78 views

#include <SoftwareSerial.h>
#defineFND_A 2 // pin match, A is pin #2
#define FND_DP 9 // pin match, DP 9 pin

int TxPin = 11; // Connect to Bluetooth TX Pin No. 2 Pin
int RxPin = 10; // Bluetooth RX pin #3 connection
SoftwareSerial BTSerial(TxPin, RxPin); 
int Sound_Sensor = A0; //Sound Detection Sensor A0 Pin Connection
int OUTPUT_pin = 13; // Connect to pin 6 of relay module connected to LED
inti,j,q,m; // repeat statement, declare variable for 7 segment control

void setup(){
 Serial.begin(9600);
  BTSerial.begin(9600);;
  pinMode(Sound_Sensor,INPUT);      //Set sound sensor to input
  pinMode (OUTPUT_pin,OUTPUT); //Set pin to output to relay module
  For (j=FND_A;j<=FND_DP;j++) // Possible because pin numbers are consecutively assigned
PinMode (j, OUTPUT); // Set pin2 to pin9 as output
}

void loop(){
  if(BTSerial.available())      
    {
      char cmd = (char)BTSerial.read();
      If(cmd=='1'){ //Application phase light on pressed to illuminate
        digitalWrite(OUTPUT_pin,HIGH);
      }else if(cmd=='0'){ //Application phase lights off pressed
        digitalWrite(OUTPUT_pin,LOW);  
      }
}
  boolean digit[11][8] = {
{1, 1, 0, 0, 1, 1, 0}, // corresponding to the number '9'
{1, 1, 1, 1, 1, 1, 1, 1, 1}, // corresponds to the number '8'
{1, 1, 0, 0, 0, 0, 0, 1}, // corresponding to the number '7'
{1, 0, 1, 1, 1, 1, 1, 1, 0}, // corresponding to the number '6'
{1, 0, 1, 1, 0, 1, 1, 0}, // corresponding to the number '5'
{0, 1, 1, 0, 0, 1, 1, 0}, // corresponding to the number '4'
{1, 1, 1, 1, 0, 0, 1, 0}, // corresponding to the number '3'
{1, 1, 0, 1, 1, 0, 1, 0}, // corresponding to the number '2'
{0, 1, 1, 0, 0, 0, 0, 0, 0}, // corresponding to the number '1'
{1, 1, 1, 1, 1, 1, 0, 0}, // corresponding to the number '0'
{0,0,0,0,0,0,0}}; 

boolean clearsegment[] = {0,0,0,0,0,0,0,0};

  if(analogRead(Sound_Sensor)>700){ // Behavior when detecting more than 700 on sound detection sensor
    For (q=0;q<=10;q++){ // Loop 10 because the number is 10 from 0 to 9
      for (j=FND_A;j<=FND_DP;j++){ // one numeric display determined
       digitalWrite(j, digit[q][j-2]); // Write the value of 1, 0 corresponding to each pin
       digitalWrite (OUTPUT_pin,HIGH); //LED ON
       }
       delay(500);
       digitalWrite (OUTPUT_pin,LOW); //LED off
       delay(500);
    if(BTSerial.available())              
    {
      char cmd = (char)BTSerial.read();
      If (cmd=='3') { //Press alarm on app to brake
        for (j=FND_A; j<= FND_DP; j++){
          digitalWrite(j, clearsegment);
        }
      break;}
    }
    }
    }
   else {
    digitalWrite (OUTPUT_pin,LOW); // Turns off after a time
  }
}

In the code above, If (cmd=='3') { //Press alarm on app to brake for (j=FND_A; j<= FND_DP; j++){ digitalWrite(j, clearsegment); } break;} When this condition is executed, I want to turn off the seven-segment screen and stop the code, but the LED stops, but the seven-segment stops at that number... I want the 7th segment to turn off, but I don't know how.

arduino

2022-09-20 12:34

1 Answers

Shouldn't it be digitalWrite(j, 0); not digitalWrite(j, clearsegment)?


2022-09-20 12:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.