Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <MCP4922.h> //DAC library from https://github.com/helgenodland/MCP4922-Arduino-SPI-Library
  2. #include <SPI.h> //Serial Peripheral Interface library used by the DAC library
  3.  
  4. MCP4922 DAC(51, 52, 53, 5); // (MOSI,SCK,CS,LDAC) define Connections for MEGA_board,
  5. //MCP4922 DAC(11,13,10,5); // (MOSI,SCK,CS,LDAC) define Connections for UNO_board,
  6.  
  7. int sampling_points = 500; //Define how many sampling points are going to draw the circle.
  8. int r = 4, g = 3, b = 2; //Define color pins
  9.  
  10. int r_v = 1, g_v = 0, b_v = 0;
  11.  
  12. void setup()
  13. {
  14. SPI.begin();
  15. setColors();
  16. }
  17.  
  18. void loop()
  19. {
  20. for (int i = 0; i < sampling_points; i++) {
  21. int x = map(
  22. sin(i * TWO_PI / sampling_points)*2048, //Compute location of sampling point.
  23. -2048, 2048, 0, 4095); //Map it to DAC code values.
  24. int y = map(
  25. cos(i * TWO_PI / sampling_points)*2048, //Compute location of sampling point.
  26. -2048, 2048, 0, 4095); //Map it to DAC code values.
  27. DAC.Set(x, y); // Send to DAC
  28. }
  29. }
  30.  
  31. void setColors() {
  32. digitalWrite(r, r_v);
  33. digitalWrite(g, g_v);
  34. digitalWrite(b, b_v);
  35. }
  36.  
  37. void resetColors() {
  38. digitalWrite(r, LOW);
  39. digitalWrite(g, LOW);
  40. digitalWrite(b, LOW);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement