Go Down

Topic: how to receive status of push button arduino via mti app inventor2 (Read 198 times) previous topic - next topic

Radwanka

i want receive status of push button and show if high or low on the smartphone. i have issue in mti app blocks

Code: [Select]

SoftwareSerial mySerial(2, 3); // Sets Arduino (RX, TX) pins
int testLED = 13; //Test LED
const int buttonPin = 8;


byte currentRead; //whats the current number we've got
byte buttonStatus = 0;
int buttonState = 0; //variable for readin the push button status

void setup() {

  pinMode(testLED, OUTPUT);
  pinMode(buttonPin, INPUT);  // Button pin
  mySerial.begin(9600);
}

void loop() {
  while (mySerial.available() > 0) {
    currentRead = mySerial.read();
        mySerial.write(buttonStatus);
      }

  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {
    buttonStatus = 20;
    digitalWrite(testLED, HIGH);
  }
    else{
    buttonStatus = 10;
    digitalWrite(testLED, LOW);
  }
  }



Moderator edit: [code] [/code] tags added.

Coding Badly


@Radwanka, do not cross-post.  Do not hijack.  Other post removed.



Coding Badly


Do not post your question in multiple places.  Pick the one you believe is the best choice then post your question in that one place.

Do not post your question to an existing thread.


PaulS

Code: [Select]
  while (mySerial.available() > 0) {
    currentRead = mySerial.read();
        mySerial.write(buttonStatus);
      }

If there is incoming serial data to read, read it AND send the value in buttonStatus, even though you haven't read the status of a button (or switch, either).

Why?

Why are you sending data before you have assigned a meaningful value to buttonStatus?

Why does sending that data depend on having received data? Why is the app sending data that you don't use?
The art of getting good answers lies in asking good questions.

Radwanka

i want use this on my car to get status of doors and lights whatever. so if one of pins are activated that send data over Bluetooth and show up on my app phone>



PaulS

Quote
i want use this on my car to get status of doors and lights whatever. so if one of pins are activated that send data over Bluetooth and show up on my app phone>
So, why are you sending data first, and then seeing if there is anything you should send?

Why are you only sending data if you have gotten data from the phone?
The art of getting good answers lies in asking good questions.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy