Guest User

code

a guest
May 5th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <Adafruit_GFX.h>
  3. #include <Adafruit_SSD1306.h>
  4. //#include <SD.h> -THE PROBLEM-
  5. //#include <SPI.h>
  6.  
  7. //A5/A4 I2C OLED
  8. /////////////////OPT means options, making a opttions menu/////////////////
  9.  
  10. int CS_PIN = 10;
  11. int opt[][4] = {{2,0,28,28},
  12. {48,0,28,28},
  13. {94,0,28,28},
  14. {2,34,28,28},
  15. {48,34,28,28},
  16. {94,34,28,28}};
  17. int buttons = 2;
  18. int shift = 1;
  19. int preshift = 1;
  20. #define OLED_RESET 4
  21. Adafruit_SSD1306 display(OLED_RESET);
  22.  
  23. void setup() {
  24. pinMode(A0, INPUT_PULLUP);
  25. pinMode(A1, INPUT_PULLUP);
  26.  
  27. Serial.begin(9600);
  28. Wire.begin();
  29. display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  30. display.clearDisplay();
  31. display.setTextColor(WHITE);
  32. display.setTextSize(1);
  33. display.setCursor(32,24);
  34. display.clearDisplay();
  35. drawOpt();
  36. display.display();
  37. }
  38.  
  39. void loop() {
  40. //LEFT = 0 DOWN = 1 UP = 2 MIDDLE = 3 RIGHT = 4 // READ FROM LEFT TO RIGHT //
  41. //if(analogRead(A0) < 18) Serial.println("left"); // LEFT
  42. //if(50 > analogRead(A0) and analogRead(A0) > 22 ) Serial.println("down"); DOWN
  43. //if(analogRead(A1) < 50 ) Serial.println("up"); UP
  44. //if(985 > analogRead(A1) and analogRead(A1) > 900 ) Serial.println("middle"); MIDDLE
  45. //if(1000 > analogRead(A1) and analogRead(A1) > 990) Serial.println("right"); // RIGHT
  46.  
  47. ///////////////////////////////////////////// JUST A WEIRD WAY OF GETTING 5/4 INPUTS FROM 2 ANALOG PINS //////////////////////////////////
  48. if(1000 > analogRead(A1) and analogRead(A1) > 990) shift = shift+1; // RIGHT //
  49. else if(analogRead(A0) < 18) shift = shift-1; // LEFT //
  50. else if(analogRead(A1) < 50 and shift > 3) shift = shift-3; // UP //
  51. else if(50 > analogRead(A0) and analogRead(A0) > 22 and shift < 4) shift = shift+3; // DOWN //
  52. if(shift == 0) shift = 6;
  53. else if(shift == 7) shift = 1;
  54. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  55.  
  56.  
  57. if(preshift != shift){
  58. preshift = shift;
  59. display.clearDisplay();
  60. drawOpt();
  61. display.display();
  62. drawSelectRect(opt[(shift-1)][0],opt[(shift-1)][1],opt[(shift-1)][2],opt[(shift-1)][3]);
  63. Serial.println(opt[(shift-1)][0]);
  64. }
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75. //x and y = top left corner position. //
  76. void drawRect(int x, int y, int width, int height) {
  77.  
  78. for(int X = x; X < (x+width+1); X=X+1) display.drawPixel(X,y, WHITE);
  79. for(int Y = y; Y < (y+height+1); Y=Y+1) display.drawPixel(x,Y, WHITE);
  80. for(int X = x; X < (x+width+1); X=X+1) display.drawPixel(X,(y+height), WHITE);
  81. for(int Y = y; Y < (y+height+1); Y=Y+1) display.drawPixel((x+height),Y, WHITE);
  82.  
  83. }
  84.  
  85. void drawSelectRect(int x, int y, int width, int height) {
  86. for(int X = (x+1); X < (x+width); X=X+1) display.drawPixel(X,(y+1), WHITE);
  87. for(int X = (x+1); X < (x+width); X=X+1) display.drawPixel(X,(y+height-1), WHITE);
  88. for(int X = (x+1); X < (x+width); X=X+1) display.drawPixel(X,(y+2), WHITE);
  89. for(int X = (x+1); X < (x+width); X=X+1) display.drawPixel(X,(y+height-2), WHITE);
  90. display.display();
  91. }
  92.  
  93.  
  94. void drawOpt() {
  95. drawRect(opt[0][0],opt[0][1],opt[0][2],opt[0][3]);
  96. drawRect(opt[1][0],opt[1][1],opt[1][2],opt[1][3]);
  97. drawRect(opt[2][0],opt[2][1],opt[2][2],opt[2][3]);
  98. drawRect(opt[3][0],opt[3][1],opt[3][2],opt[3][3]);
  99. drawRect(opt[4][0],opt[4][1],opt[4][2],opt[4][3]);
  100. drawRect(opt[5][0],opt[5][1],opt[5][2],opt[5][3]);
  101. }
Advertisement
Add Comment
Please, Sign In to add comment