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

View file

@ -1,18 +1,22 @@
#include "SerialTransfer.h"
SerialTransfer transfer;
SerialTransfer myTransfer;
const byte OC1A_PIN = 9;
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);
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);
// Clear Timer1 control and count registers
@ -27,20 +31,28 @@ void setup() {
// ICNC1 = 0b0 (Input capture noise canceler disabled)
// ICES1 = 0b0 (Input capture edge select disabled)
// CS(12:10) = 0b001 (Input clock select = clock/1)
TCCR1A |= (1 << COM1A1) | (1 << WGM11);
TCCR1B |= (1 << WGM13) | (1 << CS10);
ICR1 = TCNT1_TOP;
}
void loop() {
if(myTransfer.available())
{
// send all received data back to Python
for(uint16_t i=0; i < myTransfer.bytesRead; i++)
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);
}
}