Go Down

Topic: Project 10 button problem (Read 1 time) previous topic - next topic


Feb 09, 2016, 10:29 pm Last Edit: Feb 10, 2016, 11:52 am by Sokosz
I have some problems while doing project no10, Zoetrope.
I have the two installed buttons, but the on/off switch doesn't work. The direction changer, and the potmeter works wll, but the first doesn't. When I press it, only the 'L' LED lights up on the board. I've checked it several times, but maybe your experienced eyes can find the mistake.

So here's my setup:

And my Code:
Code: [Select]
const int controlPin1 = 2;
const int controlPin2 = 3;
const int enablePin = 9;
const int directionSwitchPin = 12;
const int onOffSwitchStateSwitchPin = 13;
const int potPin = A0;

int onOffSwitchState = 0;
int previousOnOffSwitchState = 0;
int directionSwitchState = 0;
int previousDirectionSwitchState = 0;
int motorEnabled = 0;
int motorSpeed = 0;
int motorDirection = 1;

void setup() {
  pinMode(directionSwitchPin, INPUT);
  pinMode(onOffSwitchStateSwitchPin, INPUT);
  pinMode(controlPin1, OUTPUT);
  pinMode(controlPin2, OUTPUT);
  pinMode(enablePin, OUTPUT);
  digitalWrite(enablePin, LOW);

void loop() {
  onOffSwitchState = digitalRead(onOffSwitchStateSwitchPin);
  directionSwitchState = digitalRead(directionSwitchPin);
  motorSpeed = analogRead(potPin)/8;
  if(onOffSwitchState != previousOnOffSwitchState) {
    if(onOffSwitchState == HIGH) {
      motorEnabled = !motorEnabled;
  if(directionSwitchState != previousDirectionSwitchState) {
    if(directionSwitchState == HIGH) {
      motorDirection = !motorDirection;
  if(motorDirection == 1) {
    digitalWrite(controlPin1, HIGH);
    digitalWrite(controlPin2, LOW);
  else {
    digitalWrite(controlPin1, LOW);
    digitalWrite(controlPin2, HIGH);
  if(motorEnabled = 1) {
    analogWrite(enablePin, motorSpeed);
  else {
    analogWrite(enablePin, 0);
  previousDirectionSwitchState =  directionSwitchState;
  previousOnOffSwitchState = onOffSwitchState;

Thanks for the help!


I would avoid using pin D13 for anything apart from driving the onboard led unless you really have to.

You (should) have the code under File -> Examples -> Starter Kit. Load it from there and see if it works. If not there's a problem with your physical setup.

You may also wish to take a look at this post.
Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield


Thanks a lot, the problem was solved. Just a tiny sign missing in the code. Thank you for you help. For cases like that, I recommend this link for everybody. It helps to compare two codes.


Go Up