Last active
May 20, 2016 11:18
-
-
Save rarrais/ad98da155927df9786b1215b201a7b4c to your computer and use it in GitHub Desktop.
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 <TimerOne.h> | |
int motorPin = 9; | |
int PWMa [] = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 14 , 28 , 42 , 42 , 42 , 42 , 56 , 70 , 84 , 98 , 112 , 126 , 140 , 168 , 224 , 252 , 281 , 309 , 337 , 365 , 393 , 421 , 449 , 463 , 477 , 519 , 547 , 575 , 589 , 617 , 645 , 659 , 687 , 701 , 729 , 743 , 772 , 786 , 814 , 828 , 842 , 856 , 870 , 884 , 898 , 912 , 926 , 940 , 954 , 968 , 982 , 982 , 996 , 996 , 996 , 1010 , 1010 , 1010 , 1010 , 1024 , 1024 , 1024 , 1024 , 1024 , 1024 , 1024 , 1010 , 1010 , 1010 , 996 , 996 , 996 , 982 , 982 , 982 , 968 , 954 , 940 , 926 , 912 , 912 , 898 , 898 , 884 , 870 , 870 , 856 , 842 , 828 , 814 , 800 , 786 , 772 , 757 , 743 , 729 , 715 , 701 , 687 , 673 , 659 , 645 , 631 , 617 , 603 , 589 , 575 , 561 , 547 , 533 , 519 , 505 , 491 , 477 , 463 , 463 , 463 , 477 , 491 , 505 , 519 , 533 , 547 , 575 , 589 , 603 , 617 , 631 , 645 , 659 , 673 , 673 , 673 , 673 , 659 , 659 , 645 , 631 , 631 , 631 , 631 , 617 , 617 , 617 , 603 , 603 , 603 , 589 , 589 , 589 , 589 , 575 , 575 , 575 , 561 , 547 , 547 , 547 , 533 , 533 , 533 , 533 , 533 , 533 , 519 , 519 , 519 , 519 , 505 , 505 , 505 , 505 , 491 , 491 , 491 , 477 , 463 , 463 , 463 , 449 , 449 , 449 , 449 , 435 , 435 , 435 , 435 , 421 , 421 , 421 , 421 , 407 , 407 , 407 , 407 , 393 , 393 , 393 , 393 , 393 , 379 , 379 , 379 , 379 , 365 , 365 , 365 , 365 , 351 , 351 , 351 , 351 , 337 , 337 , 337 , 337 , 337 , 323 , 323 , 323 , 323 , 309 , 309 , 309 , 309 , 295 , 295 , 295 , 295 , 295 , 281 , 281 , 281 , 281 , 267 , 267 , 267 , 267 , 267 , 252 , 252 , 252 , 252 , 238 , 238 , 238 , 238 , 238 , 224 , 224 , 224 , 224 , 210 , 210 , 210 , 210 , 210 , 196 , 196 , 196 , 196 , 196 , 182 , 182 , 182 , 182 , 182 , 168 , 168 , 168 , 168 , 168 , 154 , 154 , 154 , 154 , 154 , 140 , 140 , 140 , 140 , 140 , 126 , 126 , 126 , 126 , 126 , 126 , 112 , 112 , 112 , 112 , 112 , 112 , 98 , 98 , 98 , 98 , 98 , 98 , 98 , 84 , 84 , 84 , 84 , 84 , 84 , 84 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 42 , 42 , 42 , 42 , 42 , 42 , 42 , 42 , 28 , 28 , 28 , 28 , 28 , 28 , 28 , 28 , 28 , 28 , 28 , 28 , 28 , 28 , 28 , 28 , 28 , 28 , 28 , 28 , 14 , 0 , 0 , 0 , 0 , 0 , 0 }; | |
float PWMb; | |
int PWMb1; | |
boolean vala = false; | |
boolean valb = false; | |
boolean parar = false; | |
void setup() | |
{ | |
Serial.begin(115200); | |
establishContact(); // send a byte to establish contact until receiver responds | |
} | |
void functionA() | |
{ | |
Serial.println("Arduino: Inside Function A!"); | |
// for (int x = 0; x <= 367; x++) | |
// { | |
// // Serial.println("Arduino: x value: " + x); | |
// Timer1.pwm(motorPin, PWMa[x]); | |
// delay (3); | |
// } | |
} | |
void functionB() | |
{ | |
for(int x = 0; x<= 196; x = x + 1) | |
{ | |
PWMb = 1000 * sin(0.016 * x); | |
PWMb1 = (int) PWMb; | |
Timer1.pwm(motorPin, PWMb1); | |
delay (10); | |
} | |
} | |
void functionParar() | |
{ | |
Timer1.pwm(motorPin, 0); | |
vala = false; | |
valb = false; | |
} | |
void establishContact() | |
{ | |
while (Serial.available() <= 0) | |
{ | |
Serial.println("Serial Not available. Will keep trying"); // send a capital S | |
delay(300); | |
} | |
} | |
void loop() | |
{ | |
Serial.println("Loop"); | |
functionA(); | |
// char val; // Data received from the serial port | |
// if (Serial.available() > 0) | |
// { // If data is available to read, | |
// val = Serial.read(); // read it and store it in val | |
// if (val == 'A') | |
// { | |
// vala = true; | |
// valb = false; | |
// parar = false; | |
// Serial.println("Arduino: recebi um A"); | |
// } | |
// else if (val == 'B') { | |
// valb = true; | |
// vala = false; | |
// parar = false; | |
// Serial.println("Arduino: recebi um B"); | |
// } | |
// else if (val == 'x') { | |
// parar = true; | |
// vala = false; | |
// valb = false; | |
// Serial.println("Arduino: recebi um x"); | |
// } | |
// } | |
// else | |
// { | |
// Serial.println("Serial Not available!"); | |
// delay(50); | |
// } | |
// if (vala == true) | |
// { | |
// Serial.println("Arduino: Starting Function A"); | |
// functionA(); | |
// } | |
// if (valb == true) | |
// { | |
// Serial.println("Arduino: Starting Function B"); | |
// functionB(); | |
// } | |
// if (parar == true) | |
// { | |
// Serial.println("Arduino: Stopping Functions"); | |
// functionParar(); | |
// } | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment