trying to build pedometer with serial monitor as display

  • Thread starter Deleted member 750607
  • Start date

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
Using arduino uno, getting error message, seems to be a syntactic error...???

had a couple other drafts, in one I was able to read on my serial monitor "1" for still accelerometer and "11" for moving accelerometer

in another, I was able to read nothing for still accelerometer, and "1" for moving accelerometer

this draft won't compile successfully

I would like it to start at 0 on serial monitor, and increase by one each time accelerometer moves on any of 3 axis

Help is appreciated, go easy on me, im a beginner

this is my code - error message: expected ')' before 'x'

C:
const int xpin = A0;
const int ypin = A1;
const int zpin = A2;
int Steps = 0;
int x = 1;

void setup()
{
pinMode (xpin, INPUT);
pinMode (ypin, INPUT);
pinMode (zpin, INPUT);

Serial.begin (9600);
}


void loop()
{
int a = analogRead (xpin);
delay (500);
int b = analogRead (ypin);
delay (500);
int c = analogRead (zpin);
delay (500);

if (a < 678)
  {
    Serial.print (Steps ++x);
  }
if (b <= 464 )
  {
    Serial.print (Steps ++x);
  }
if (c <=4 )
   {
    Serial.print (Steps ++x);
   }
if (a >= 680)
  {
    Serial.print (Steps ++x);
  }
if (b >= 674)
  {
    Serial.print (Steps ++x);
  }
if (c > 6)
{
   Serial.print (Steps ++x);
}
}
Moderators note : used code tags
 
Last edited by a moderator:

djsfantasi

Joined Apr 11, 2010
9,156
What is the variable Steps used for? You define it and never change it.

I have a thought that you may want to display the word Steps on the display... Is that the case? Then, you don’t need a variable. Just refer to it by a character constant.

Serial.println( “Steps “, ++x);​
 

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
thanks to all of you. I've got it working how I want now, with this code

const int xpin = A0;
const int ypin = A1;
const int zpin = A2;
int Steps = 0;

void setup()
{
pinMode (xpin, INPUT);
pinMode (ypin, INPUT);
pinMode (zpin, INPUT);

Serial.begin (9600);
}


void loop()
{
int x = analogRead (xpin);
delay (500);
int y = analogRead (ypin);
delay (500);
int z = analogRead (zpin);
delay (500);

if (z <= 4)
{
Serial.println (Steps++);
}
}
 
Top