i imported to Atmel Studio, and successfully compiled, the sketch below, filename Sketch.cpp
Then i removed Sketch.cpp , and replaced it with the following main.c. main.c is my handwritten attempt to write the sketch in C-style.
On build, got many errors.
I'm trying this approach, because some in the forum have commented that getting all the library referenced correct in AS is very challenging.
Is there a right way to do this? -thx
sketch.cpp
/*Begining of Auto generated code by Atmel studio */ #include <Arduino.h> /*End of auto generated code by Atmel studio */ /*************************************************** for Adafruit 16-channel PWM & Servo driver PWM test - this will drive 16 PWMs in a 'wave' These drivers use I2C to communicate, 2 pins are required to interface. ****************************************************/ #include <Wire.h> #include <Adafruit_PWMServoDriver.h> //Beginning of Auto generated function prototypes by Atmel Studio //End of Auto generated function prototypes by Atmel Studio // called this way, it uses the default address 0x40 Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); // you can also call it with a different address you want //Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41); // you can also call it with a different address and I2C interface //Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(&Wire, 0x40); void setup() { Serial.begin(9600); Serial.println("16 channel PWM test!"); pwm.begin(); pwm.setPWMFreq(1600); // This is the maximum PWM frequency // if you want to really speed stuff up, you can go into 'fast 400khz I2C' mode // some i2c devices dont like this so much so if you're sharing the bus, watch // out for this! Wire.setClock(400000); } void loop() { // Drive each PWM for (uint16_t i=0; i<4096; i += 8) { for (uint8_t pwmnum=0; pwmnum < 16; pwmnum++) { pwm.setPWM(pwmnum, 0, (i + (4096/16)*pwmnum) % 4096 ); } #ifdef ESP8266 yield(); // take a breather, required for ESP8266 #endif } }
main.c
#include <Wire.h> #include <Adafruit_PWMServoDriver.h> // called this way, it uses the default address 0x40 Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); // you can also call it with a different address you want //Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41); // you can also call it with a different address and I2C interface //Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(&Wire, 0x40); int main(void) { // Arduino "Setup" Serial.begin(9600); Serial.println("16 channel PWM test!"); pwm.begin(); pwm.setPWMFreq(1600); // This is the maximum PWM frequency Wire.setClock(400000); // Arduino "Loop" while (1) { // Drive each PWM in a 'wave' for (uint16_t i=0; i<4096; i += 8) { for (uint8_t pwmnum=0; pwmnum < 16; pwmnum++) { pwm.setPWM(pwmnum, 0, (i + (4096/16)*pwmnum) % 4096 ); } #ifdef ESP8266 yield(); // take a breather, required for ESP8266 #endif } } }