Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #include <wiringpi.h>
  2. #include <wiringPiSPI.h>
  3. #include <softPwm.h>
  4. #include <bool.h>
  5.  
  6. //declare global booleans and variables.
  7. #define button = true;
  8.  
  9. void button_thread() {
  10. while(){
  11. //Detect buttons change booleans and values.
  12. //Update screen.
  13. }
  14. }
  15.  
  16. int main(int argc, char *argv[]) {
  17. printf("Initializing setup...\n");
  18. // start bridge SPI
  19. // set SPI channel to 0 and speed to 16MHz
  20. if (wiringPiSPISetup(0, 16000000) < 0) {
  21. fprintf(stderr, "Could not setup WiringPi SPI.\n", sterror (errno));
  22. exit(1);
  23. }
  24. // start wiringpi setup
  25. if (wiringPiSetup() < 0) {
  26. fprintf(stderr, "Could not setup WiringPi.\n", sterror (errno));
  27. exit(1);
  28. }
  29.  
  30. printf("Starting... \n");
  31.  
  32. pinMode(13, INPUT); //MISO will use pin 13
  33. pinMode(1, OUTPUT); //GPIO1 will be used for PWM (analog output)
  34.  
  35. uint8_t mosi[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  36. uint8_t miso[10] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  37. // define I/O
  38. // define lcd
  39. // start thread buttons and switches.
  40.  
  41. while(1) {
  42. //receive data
  43. wiringPiSPIDataRW(0, miso, 10); //SPI transfer to transfer 10 bits to the miso list.
  44.  
  45. //effect function
  46. //if (button) {
  47. // miso = distortion();
  48. //}
  49. printf("Data received: " + miso + "\n");
  50. //output
  51. int data = miso[2] + ((miso[1] & 0x0F) << 8); //MISO value represented in percentage for PWM
  52. //unsure about this equation but will know more about the input we receive when we do some testing.
  53.  
  54. // softPwmWrite(1, data);
  55. miso = mosi; //reset miso to be all 0's again.
  56. }
  57. return 0;
  58. }
  59.  
  60. uint8_t distortion() {
  61. //individual functions for each effect for clean code
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement