Files
monocoque/src/arduino/simwind/simwind.ino
T

44 lines
916 B
Arduino
Raw Normal View History

2023-05-17 15:56:57 +00:00
#include <Adafruit_MotorShield.h>
#include "simwind.h"
2023-05-17 15:56:57 +00:00
#define BYTE_SIZE sizeof(SimWindData)
2023-05-17 15:56:57 +00:00
#define KPHTOMPH .621317
2024-02-17 18:50:57 +00:00
#define FANPOWER .6
2023-05-17 15:56:57 +00:00
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *myMotor1 = AFMS.getMotor(1);
Adafruit_DCMotor *myMotor2 = AFMS.getMotor(3);
2024-03-05 00:34:29 -05:00
SimWindData sd;
2023-05-17 15:56:57 +00:00
int velocity = 0;
void setup() {
2024-09-19 17:05:42 -04:00
Serial.begin(9600);
2023-05-17 15:56:57 +00:00
if (!AFMS.begin()) {
Serial.println("Could not find Motor Shield. Check wiring.");
while (1);
}
sd.velocity = 10;
myMotor1->setSpeed(0);
myMotor1->run(FORWARD);
myMotor2->setSpeed(0);
myMotor2->run(FORWARD);
}
void loop() {
char buff[BYTE_SIZE];
if (Serial.available() >= BYTE_SIZE)
{
Serial.readBytes(buff, BYTE_SIZE);
memcpy(&sd, &buff, BYTE_SIZE);
velocity = sd.velocity;
}
2024-09-19 17:05:42 -04:00
myMotor1->setSpeed(velocity*FANPOWER);
myMotor2->setSpeed(velocity*FANPOWER);
2023-05-17 15:56:57 +00:00
}