This commit is contained in:
askiiart 2022-10-24 22:21:16 -05:00
parent df96317249
commit 0f4e189a6b

View file

@ -1,17 +1,21 @@
#include "SerialTransfer.h" #include "SerialTransfer.h"
SerialTransfer transfer; SerialTransfer myTransfer;
const byte OC1A_PIN = 9; const byte OC1A_PIN = 9;
const byte OC1B_PIN = 10; const byte OC1B_PIN = 10;
const word PWM_FREQ_HZ = 25000; //Adjust this value to adjust the frequency (Frequency in HZ!) (Set currently to 25kHZ) const word PWM_FREQ_HZ = 25000; //Adjust this value to adjust the frequency (Frequency in HZ!) (Set currently to 25kHZ)
const word TCNT1_TOP = 16000000/(2*PWM_FREQ_HZ); const word TCNT1_TOP = 16000000/(2*PWM_FREQ_HZ);
struct STRUCT {
char val;
} myStruct;
void setup() { void setup() {
// Setup Serial transfer with PC // Setup Serial transfer with PC
Serial.begin(115200); Serial.begin(115200);
transfer.begin(Serial); myTransfer.begin(Serial);
pinMode(OC1A_PIN, OUTPUT); pinMode(OC1A_PIN, OUTPUT);
@ -34,13 +38,21 @@ void setup() {
} }
void loop() { void loop() {
if(myTransfer.available()) if(myTransfer.available())
{ {
// send all received data back to Python
for(uint16_t i=0; i < myTransfer.bytesRead; i++)
myTransfer.packet.txBuff[i] = myTransfer.packet.rxBuff[i];
// send all received data back to Python
for(uint16_t i=0; i < myTransfer.bytesRead; i++){
myTransfer.packet.txBuff[i] = myTransfer.packet.rxBuff[i];
}
myTransfer.sendData(myTransfer.bytesRead); myTransfer.sendData(myTransfer.bytesRead);
uint16_t recSize = 0;
recSize = myTransfer.rxObj(myStruct, recSize);
int x = myStruct.val * 2;
setPwmDuty(x);
} }
} }