2

I am using Codeblocks with arduino IDE to simulate the control of a stepper motor, and the errors "'analogRead' was not declared in this scope" and "'A0' was not declared in this scope" keep popping. The code follows:

#include <Stepper.h>

const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int stepCount = 0;  // number of steps the motor has taken

void setup() {
}

void loop()
{
    int sensorReading = analogRead(A0); //ERROR

    int motorSpeed = map(sensorReading, 0, 1023, 0, 100);

    if (motorSpeed > 0)
    {
        myStepper.setSpeed(motorSpeed);
        myStepper.step(stepsPerRevolution / 100);
    }
}

EDIT: Sorry I forgot to mention it clear, but I do not own a board, that's why I'm trying to simulate it on PC.

5
  • 2
    Did you follow the rest of the process to integrate the Arduino environment into Codeblocks? – Ignacio Vazquez-Abrams May 11 '17 at 0:34
  • 1
    @IgnacioVazquez-Abrams Do you have a link to this process? – sa_leinad May 11 '17 at 1:31
  • did you try to include "Arduino.h"? – Rafael Alexandre Oct 19 '18 at 3:00
  • Did you get this issue fixed? If so, could you post an answer as to how you fixed it? – Greenonline Apr 18 '19 at 10:20
  • Also, which version of codeblocks? – Greenonline Apr 18 '19 at 10:29
-1

// yours code looks Ok, but i think problem is with Arduio IDE setting. Go to the "Tool > Boards...." in arduino IDE and make it sure that you have selected the right option of Arduino module. Mean it is same as you are using in hardware?

1
  • 3
    He is using Codeblocks IDE with Arduino core, not the actual Arduino IDE. – gre_gor May 11 '17 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.