I am a newbie, and I cobbled together some arduino code to run a peristaltic pump hooked up to a CPX and Crickit.
My code compiles and runs fine and lights up the neopixels no problem, but I cannot get the motor to run when either the left or right CPX buttons are pressed.
It must be a fault in my logic or code, as I can get the motor to run with the CPX example sketch: dual motor demo.
Any help would be appreciated.
-----------------------------------
Code: Select all
#include "Adafruit_Crickit.h"
#include "seesaw_motor.h"
#include <Adafruit_CircuitPlayground.h>
bool leftButtonPressed;
bool rightButtonPressed;
int leftbuttonmotordelay = 5000;
int rightbuttonmotordelay = 1000;
Adafruit_Crickit crickit;
seesaw_Motor motor_a(&crickit);
void setup()
{ CircuitPlayground.begin();
//attach motor a
motor_a.attach(CRICKIT_MOTOR_A1, CRICKIT_MOTOR_A2);
Serial.begin(9600); // set up Serial library at 9600 bps
}
void loop() {
CircuitPlayground.clearPixels();
CircuitPlayground.setPixelColor(4, 255, 0, 0);
delay(1000);
CircuitPlayground.setPixelColor(2, 255, 0, 0);
Serial.println("Hello world!"); // prints hello with ending line break
delay(1000);
leftButtonPressed = CircuitPlayground.leftButton();
rightButtonPressed = CircuitPlayground.rightButton();
if (leftButtonPressed) {
CircuitPlayground.setPixelColor(2, 255, 0, 0);
motor_a.throttle(1);
CircuitPlayground.setPixelColor(0, 255, 0, 0);
delay(leftbuttonmotordelay);}
else {
motor_a.throttle(0);;
}
if (rightButtonPressed) {
motor_a.throttle(1);
CircuitPlayground.setPixelColor(2, 0, 255, 0);
delay(rightbuttonmotordelay);}
else {
motor_a.throttle(0);;
}
// exit the loop
//exit(0); //0 is required to prevent error.
}