i need help

if (incomingByte == 'A') {
      test = 1;
      delay(200);                        // Required delay
  mySerial.print("Loading");
      mySerial.write(13);                 // Form feed
  mySerial.print("    test");
      delay(3000);
      while(test = 1){  
       sensorValue = analogRead(sensorPin);            
  float voltage = sensorValue * (100.00 / 1023.0);
  mySerial.write(12);                 // Clear 
  delay(5);                           // Required delay
  mySerial.print("Power");  // First line
  mySerial.write(13);                 // Form feed
  mySerial.print(voltage);   // Second line
  //mySerial.write(212);                // Quarter note

  //mySerial.write(220);                // A tone                 // Clear 
  delay(500);                        // Wait 3 seconds

i cant perform anything while test = 1 but i want the chip to simultaneously refresh a parallax 2x16 screen and recognize another if statement
should i use an else statement or should i look into a FPGA?

I suspect the solution is to remove the delay() statements and get the same effect with the techniques in the "blink without delay" example.

...R

A few pointers

  1. Before posting always layout the code - see the auto format command in the IDE. It helps us help you!

  2. = is the assignment op and not the equality operator, which is ==

  3. Read the sticky at the top of the forum

  4. Always post all your code!

  5. Never use delay()

Mark

Perhaps you should first investigate the difference between

while ( test = 1 )

and

while ( test == 1 )

although in the case shown it doesn't make much difference because the value of test never changes.

Furthermore, in the long run those delay statements are going to hurt you. For example, delay(3000) means
"Waste all of the Arduino's considerable processing power for at least 3 seconds".

Instead, look at the Blink Without Delay example. I don't have a link handy, but perhaps others will respond and provide the link.

int sensorPin = A3;
const int ledPin = 13;// the pin that the LED is attached to
const int ledPin1 = 12;
const int ledPin2 = 10;
const int ledPin3 = 8;
int sensorValue = 0;
int incomingByte;      // a variable to read incoming serial data into
int test = 0;
const int TxPin = 6;


#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(255, TxPin);


void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(TxPin, OUTPUT);
  digitalWrite(TxPin, HIGH);


  mySerial.begin(9600);
  mySerial.write(17);                 // Turn backlight on

}


void loop() {
  // see if there's incoming serial data:
  sensorValue = analogRead(sensorPin);  
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    // if it's a capital H (ASCII 72), turn on the LED:
    if (incomingByte == 'H') {
      digitalWrite(ledPin, HIGH);
      delay(sensorValue);
      digitalWrite(ledPin,LOW);
      delay(sensorValue);
      digitalWrite(ledPin1, HIGH);
      delay(sensorValue);
      digitalWrite(ledPin1,LOW);
      delay(sensorValue);
      digitalWrite(ledPin2, HIGH);
      delay(sensorValue);
      digitalWrite(ledPin2,LOW);
      delay(sensorValue);
      digitalWrite(ledPin3, HIGH);
      delay(sensorValue);
      digitalWrite(ledPin3,LOW);
      delay(sensorValue);
    } 
    // if it's an L (ASCII 76) turn off the LED:
    if (incomingByte == 'A') {
      test == 1;
      delay(200);                        // Required delay
      mySerial.print("Test");
      mySerial.write(13);                 // Form feed
      mySerial.print("    1234");
      delay(3000);
      while(test = 1){  
        sensorValue = analogRead(sensorPin);            
        float voltage = sensorValue * (100.00 / 1023.0);
        mySerial.write(12);                 // Clear 
        delay(5);                           // Required delay
        mySerial.print("voltage");  // First line
        mySerial.write(13);                 // Form feed
        mySerial.print(voltage);   // Second line
        //mySerial.write(212);                // Quarter note

          //mySerial.write(220);                // A tone                 // Clear 
        delay(500);                        // Wait 3 seconds
      }  
    }



    //mySerial.write(18);                 // Turn backlight off 
    //mySerial.write(18);                 // Turn backlight off     


  }
}

here is the code in its entirety…the delay(3000); is only used to hold test 1234 on the screen so it is not automatically cleared before the censor value is shown… this is just a test but i want the led to cut on and off according to the sensorvalue and display said value on the screen at the same time but only when it receives the A byte

while(test = 1){
sensorValue = analogRead(sensorPin);
float voltage = sensorValue * (100.00 / 1023.0);
mySerial.write(12); // Clear
delay(5); // Required delay
mySerial.print("voltage"); // First line
mySerial.write(13); // Form feed
mySerial.print(voltage); // Second line
//mySerial.write(212); // Quarter note

is used to refresh the screen to gain a new "sensorValue"

had a long night so bare with me...

 while(test = 1){

is an assignment! not a test of the value of “test”! Grrrrr

Mark

holmes4:

 while(test = 1){

is an assignment! not a test of the value of "test"! Grrrrr

Mark

smh does it really make that much a difference

still works the same and i save a whole byte lol

i think i might use a another analog pin to change the value of test...but that is another part and pin...

Once you are in the while loop you will stay there for ever!

Mark

holmes4:
Once you are in the while loop you will stay there for ever!

Mark

Indeed... now what can i do besides locking the processor with while statement? :stuck_out_tongue:

look at your code ( I've put it between quote tags so that I can change the text color as needed):

// if it's an L (ASCII 76) turn off the LED: you should change your comments when code changes
if (incomingByte == 'A') {
test == 1; // ??? "==" is an equality test, not an assignment
delay(200); // Required delay
mySerial.print("Test");
mySerial.write(13); // Form feed
mySerial.print(" 1234");
delay(3000);
while(test = 1){ // ?? "=" is an assignment, not a test
sensorValue = analogRead(sensorPin);
float voltage = sensorValue * (100.00 / 1023.0);
mySerial.write(12); // Clear
delay(5); // Required delay // why is it required ?
mySerial.print("voltage"); // First line
mySerial.write(13); // Form feed
mySerial.print(voltage); // Second line
//mySerial.write(212); // Quarter note

//mySerial.write(220); // A tone // Clear
delay(500); // Wait 3 seconds // 3 seconds ??
}
}

As you can see, you don't change the test value, then you're stuck in the while loop.
May I suggest that you learn the C/C++ basics ( operators, functions ) and then have a look at this page
Gammon Forum : Electronics : Microprocessors : How to process incoming serial data without blocking to see how to deal with serial datas ?

i got it now guys thanks
with no added parts... i just get tired and make some stupid mistakes i am
the while statement was not needed at all

just move the whole function to the beginning of the loop...

but ill take note of the advice XD

i scrap code to speed things up i know its a messy way of doing things but all it has to do is work right

i do have plenty of c++ books though i am just hacker/hobbyist with no formal eduction in programming... live and learn applies

Learn the difference between = and == or you will have a lot of sleepless nights.

It doesn't save a byte in the compiled code, it just tells the compiler what you want to do.

...R