Last active
August 29, 2015 14:24
-
-
Save mithi/310d4143386252368a70 to your computer and use it in GitHub Desktop.
drawing crazy patterns with arcbotics sparki
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Sparki.h> | |
class Patterns{ | |
public: | |
Patterns(){ | |
} | |
void turnSignal(){ | |
int colors[3][3] = {RGB_RED, RGB_BLUE, RGB_GREEN}; | |
sparki.beep(); | |
for (int x = 0; x < 3; x++){ | |
sparki.RGB(colors[x][0], colors[x][1], colors[x][2]); | |
delay(250); | |
} | |
sparki.RGB(RGB_OFF); | |
} | |
void stopSignal(){ | |
for (int x = 1; x < 10; x++){ | |
sparki.beep(); | |
sparki.RGB(50, 0, 100); | |
delay(200); | |
} | |
sparki.RGB(RGB_OFF); | |
} | |
void stopMotors(){ | |
sparki.motorStop(MOTOR_LEFT); | |
sparki.motorStop(MOTOR_RIGHT); | |
stopSignal(); | |
} | |
void forwardWheels(int leftSpeed, int rightSpeed, int waitmSec) { | |
turnSignal(); | |
sparki.motorRotate(MOTOR_LEFT, DIR_CCW, leftSpeed); | |
sparki.motorRotate(MOTOR_RIGHT, DIR_CW, rightSpeed); | |
delay(waitmSec); | |
} | |
void reverseWheels(int leftSpeed, int rightSpeed, int waitmSec) { | |
turnSignal(); | |
sparki.motorRotate(MOTOR_LEFT, DIR_CW, leftSpeed); | |
sparki.motorRotate(MOTOR_RIGHT, DIR_CCW, rightSpeed); | |
delay(waitmSec); | |
} | |
void crazySun(int speed1, int speed2, int waitmSec, unsigned long timeToDo){ | |
unsigned long endTime = millis() + timeToDo; | |
while(millis() < endTime){ | |
forwardWheels(speed1, speed2, waitmSec); | |
reverseWheels(speed2, speed1, waitmSec); | |
} | |
stopMotors(); | |
} | |
void squigglyLines(int speed1, int speed2, int waitmSec, int num){ | |
for (int x=0; x<num; x++){ | |
forwardWheels(speed1, speed2, waitmSec); | |
forwardWheels(speed2, speed1, waitmSec); | |
} | |
stopMotors(); | |
} | |
void circle(int speed1, int speed2, int waitmSec, unsigned long timeToDo){ | |
unsigned long endTime = millis() + timeToDo; | |
while(millis() < endTime) { | |
forwardWheels(speed1, speed2, waitmSec); | |
} | |
stopMotors(); | |
} | |
void hourglassHelper(int x1, int x2, int w){ | |
sparki.moveForward(x1); | |
sparki.moveLeft(90); | |
sparki.moveForward(w); | |
sparki.moveLeft(90); | |
sparki.moveForward(x2); | |
sparki.moveRight(90); | |
sparki.moveForward(w); | |
sparki.moveRight(90); | |
} | |
void hourglass(int l, int w){ | |
for(int x = l; x > 0; x-=2){ | |
hourglassHelper(x, x-1, w); | |
} | |
turnSignal(); | |
for(int x = 1; x < l; x+=2){ | |
hourglassHelper(x, x+1, w); | |
} | |
stopMotors(); | |
} | |
void mazeHelperRight(int x){ | |
sparki.moveForward(x); | |
sparki.moveRight(90); | |
} | |
void mazeHelperLeft(int x){ | |
sparki.moveForward(x); | |
sparki.moveLeft(90); | |
} | |
void maze(int l, int w){ | |
for (int x = 1; x <= 2*l; x+=w){ | |
mazeHelperRight(x); | |
} | |
sparki.moveRight(270); | |
for (int x = 2*l; x > 0; x-=w){ | |
mazeHelperLeft(x); | |
} | |
stopMotors(); | |
} | |
void spiral(int length){ | |
if (length > 100){ | |
length = 100; | |
} | |
forwardWheels(100,1, 1000); | |
for (int i=1; i <=length; i++){ | |
forwardWheels(100, i, i*200); | |
} | |
sparki.moveStop(); | |
} | |
void veeness(int x, int d, int n, int theta){ | |
int phi = 180 -2*theta; | |
int alpha = 180 - phi; | |
int beta = 90 + theta; | |
int gamma = 90 - theta; | |
for (int i = 0; i < n; i++){ | |
sparki.moveLeft(gamma); | |
sparki.moveForward(x); | |
sparki.moveLeft(alpha); | |
sparki.moveForward(x); | |
sparki.moveRight(beta); | |
sparki.moveForward(d); | |
sparki.moveRight(gamma); | |
sparki.moveForward(x); | |
sparki.moveRight(alpha); | |
sparki.moveForward(x); | |
sparki.moveLeft(beta); | |
sparki.moveForward(d); | |
} | |
stopMotors(); | |
} | |
void abstractLHelper(int x, int d, int n){ | |
for(int i=0; i<n; i++){ | |
sparki.moveLeft(90); | |
sparki.moveForward(x); | |
sparki.moveRight(90); | |
sparki.moveForward(d); | |
sparki.moveRight(90); | |
sparki.moveForward(x); | |
sparki.moveLeft(90); | |
sparki.moveForward(d); | |
} | |
} | |
void abstractL(int x, int d, int n){ | |
abstractLHelper(x, d, n); | |
sparki.moveForward(x+2); | |
sparki.moveLeft(90); | |
sparki.moveForward(d); | |
abstractLHelper(x, d, n); | |
stopMotors(); | |
} | |
}; | |
Patterns pattern; | |
void setup(){ | |
//pattern.crazySun(50, 100, 4000, 128000); | |
//pattern.squigglyLines(5, 100, 8000, 5); | |
//pattern.circle(5, 100, 8000, 24000); | |
//pattern.hourglass(20,1); | |
//pattern.maze(10,1); | |
//pattern.spiral(50); | |
//pattern.abstractL(5, 2, 4); | |
pattern.veeness(8, 2, 7, 30); | |
} | |
void loop(){ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment