/********************************************************************** This is a quick-and-dirty driver program to test the library of routines written by Sarvesh Kulkarni for Adafruit's PCA9685 based 16 channel PWM board. *********************************************************************/ #include "adafruit_pca9685_pwm_driver.h" #include using namespace std; int main() { int menu(void); int choice; float dc = 20, delay = 0, freq; int ch_num = 0, ret_code; PWM_Board my_pwm; choice = menu(); while (1) { switch (choice) { case 1: cout << "\nFreq (Hz) ? --> "; // affects all channels cin >> freq; ret_code = my_pwm.setFreq(freq); if(ret_code < 0) cout << "\n ERROR in setting Frequency - Err Code " << ret_code << endl; choice = menu(); break; case 2: cout << "\nDuty Cycle (%), Channel Num, Delay (%) ? --> "; cin >> dc >> ch_num >> delay; cout << "\n Setting duty cycle: " << dc; cout << ", Channel no: " << ch_num << ", Delay: " << delay << endl; ret_code = my_pwm.setDutyCycle(dc, ch_num, delay); if(ret_code < 0) cout << "\n ERROR in setting Duty Cycle - Err Code " << ret_code << endl; choice = menu(); break; case 3: ret_code = my_pwm.sleep(); if(ret_code < 0) cout << "\n ERROR in Sleeping - Err Code " << ret_code << endl; choice = menu(); break; case 4: ret_code = my_pwm.soft_reset(); if(ret_code < 0) cout << "\n ERROR in Sodt Reset - Err Code " << ret_code << endl; choice = menu(); break; case 5: ret_code = my_pwm.hard_reset(); if(ret_code < 0) cout << "\n ERROR in Hard Reset - Err Code " << ret_code << endl; choice = menu(); break; default: cout <<" Quitting!" << endl << endl; return 0; break; } // switch } // while } int menu(void) { int sel; cout << endl << " Select a Routine to test:" << endl; cout << " (1): Set Frequency" << endl; cout << " (2): Set Duty Cycle" << endl; cout << " (3): Sleep" << endl; cout << " (4): Soft Reset" << endl; cout << " (5): Hard Reset" << endl; cout << " (6): Exit --> "; cin >> sel; cout << endl << endl; return sel; }