#define CUSTOM_SETTINGS
#define INCLUDE_TERMINAL_SHIELD
#define INCLUDE_COLOR_DETECTOR_SHIELD
#include <OneSheeld.h>
unsigned long white = 0xFFFFFF;
int motor1PWM = 3;
int motor1DIR = 4;
int motor2PWM = 6;
int motor2DIR = 7;
void setup() {
OneSheeld.begin();
ColorDetector.setOnSelected(&selected);
pinMode(motor1PWM, OUTPUT);
pinMode(motor1DIR, OUTPUT);
pinMode(motor2PWM, OUTPUT);
pinMode(motor2DIR, OUTPUT);
digitalWrite(motor1DIR, LOW);
digitalWrite(motor2DIR, HIGH);
}
void loop() {
}
void selected()
{
ColorDetector.setPalette(_3_BIT_RGB_PALETTE);
ColorDetector.enableFullOperation();
ColorDetector.setCalculationMode(MOST_DOMINANT_COLOR);
ColorDetector.setOnNewColor(&newColor);
}
void newColor(Color one,Color two,Color three,Color four,Color five,Color six,Color seven,Color eight,Color nine)
{
if (three == white && one == white)
{ moveForward(); }
else if (three == white && one != white)
{ moveLeft(); }
else if (one == white && three != white)
{ moveRight(); }
}
void moveForward()
{
analogWrite(motor1PWM, 25);
analogWrite(motor2PWM, 25);
}
void moveRight()
{
analogWrite(motor1PWM, 20);
analogWrite(motor2PWM, 12);
}
void moveLeft()
{
analogWrite(motor1PWM, 12);
analogWrite(motor2PWM, 20);
}
Comments
Please log in or sign up to comment.