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

View file

@ -1,6 +1,6 @@
#include "SerialTransfer.h"
SerialTransfer transfer;
SerialTransfer myTransfer;
const byte OC1A_PIN = 9;
const byte OC1B_PIN = 10;
@ -8,10 +8,14 @@ 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 TCNT1_TOP = 16000000/(2*PWM_FREQ_HZ);
struct STRUCT {
char val;
} myStruct;
void setup() {
// Setup Serial transfer with PC
Serial.begin(115200);
transfer.begin(Serial);
myTransfer.begin(Serial);
pinMode(OC1A_PIN, OUTPUT);
@ -34,13 +38,21 @@ void setup() {
}
void loop() {
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);
uint16_t recSize = 0;
recSize = myTransfer.rxObj(myStruct, recSize);
int x = myStruct.val * 2;
setPwmDuty(x);
}
}