// pwm-08: adapted from Sarvesh Kulkarni's main.cc // // Changes: enclosed the code in extern "C", added #include "pwm.h", // changed main to pwm_test, made my_pwm static and global, and added // C interfaces to the PWM_Board public methods. // // R. Perry, April 2013 /********************************************************************** 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; #include "pwm.h" extern "C" { static PWM_Board my_pwm; int pwm_test() { int menu(void); int choice; float dc = 20, delay = 0, freq; int ch_num = 0, ret_code; 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; } // C interfaces to the PWM_Board public methods // int pwm_isInitialized( void) { return my_pwm.isInitialized(); } int pwm_setFreq( float freq) { return my_pwm.setFreq(freq); } int pwm_setDutyCycle( float duty_cycle, int channel_num, float delay ) { return my_pwm.setDutyCycle( duty_cycle, channel_num, delay); } int pwm_sleep( void) { return my_pwm.sleep(); } int pwm_soft_reset( void) { return my_pwm.soft_reset(); } int pwm_hard_reset( void) { return my_pwm.hard_reset(); } }