Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- //#include <SD.h> -THE PROBLEM-
- //#include <SPI.h>
- //A5/A4 I2C OLED
- /////////////////OPT means options, making a opttions menu/////////////////
- int CS_PIN = 10;
- int opt[][4] = {{2,0,28,28},
- {48,0,28,28},
- {94,0,28,28},
- {2,34,28,28},
- {48,34,28,28},
- {94,34,28,28}};
- int buttons = 2;
- int shift = 1;
- int preshift = 1;
- #define OLED_RESET 4
- Adafruit_SSD1306 display(OLED_RESET);
- void setup() {
- pinMode(A0, INPUT_PULLUP);
- pinMode(A1, INPUT_PULLUP);
- Serial.begin(9600);
- Wire.begin();
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
- display.clearDisplay();
- display.setTextColor(WHITE);
- display.setTextSize(1);
- display.setCursor(32,24);
- display.clearDisplay();
- drawOpt();
- display.display();
- }
- void loop() {
- //LEFT = 0 DOWN = 1 UP = 2 MIDDLE = 3 RIGHT = 4 // READ FROM LEFT TO RIGHT //
- //if(analogRead(A0) < 18) Serial.println("left"); // LEFT
- //if(50 > analogRead(A0) and analogRead(A0) > 22 ) Serial.println("down"); DOWN
- //if(analogRead(A1) < 50 ) Serial.println("up"); UP
- //if(985 > analogRead(A1) and analogRead(A1) > 900 ) Serial.println("middle"); MIDDLE
- //if(1000 > analogRead(A1) and analogRead(A1) > 990) Serial.println("right"); // RIGHT
- ///////////////////////////////////////////// JUST A WEIRD WAY OF GETTING 5/4 INPUTS FROM 2 ANALOG PINS //////////////////////////////////
- if(1000 > analogRead(A1) and analogRead(A1) > 990) shift = shift+1; // RIGHT //
- else if(analogRead(A0) < 18) shift = shift-1; // LEFT //
- else if(analogRead(A1) < 50 and shift > 3) shift = shift-3; // UP //
- else if(50 > analogRead(A0) and analogRead(A0) > 22 and shift < 4) shift = shift+3; // DOWN //
- if(shift == 0) shift = 6;
- else if(shift == 7) shift = 1;
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- if(preshift != shift){
- preshift = shift;
- display.clearDisplay();
- drawOpt();
- display.display();
- drawSelectRect(opt[(shift-1)][0],opt[(shift-1)][1],opt[(shift-1)][2],opt[(shift-1)][3]);
- Serial.println(opt[(shift-1)][0]);
- }
- }
- //x and y = top left corner position. //
- void drawRect(int x, int y, int width, int height) {
- for(int X = x; X < (x+width+1); X=X+1) display.drawPixel(X,y, WHITE);
- for(int Y = y; Y < (y+height+1); Y=Y+1) display.drawPixel(x,Y, WHITE);
- for(int X = x; X < (x+width+1); X=X+1) display.drawPixel(X,(y+height), WHITE);
- for(int Y = y; Y < (y+height+1); Y=Y+1) display.drawPixel((x+height),Y, WHITE);
- }
- void drawSelectRect(int x, int y, int width, int height) {
- for(int X = (x+1); X < (x+width); X=X+1) display.drawPixel(X,(y+1), WHITE);
- for(int X = (x+1); X < (x+width); X=X+1) display.drawPixel(X,(y+height-1), WHITE);
- for(int X = (x+1); X < (x+width); X=X+1) display.drawPixel(X,(y+2), WHITE);
- for(int X = (x+1); X < (x+width); X=X+1) display.drawPixel(X,(y+height-2), WHITE);
- display.display();
- }
- void drawOpt() {
- drawRect(opt[0][0],opt[0][1],opt[0][2],opt[0][3]);
- drawRect(opt[1][0],opt[1][1],opt[1][2],opt[1][3]);
- drawRect(opt[2][0],opt[2][1],opt[2][2],opt[2][3]);
- drawRect(opt[3][0],opt[3][1],opt[3][2],opt[3][3]);
- drawRect(opt[4][0],opt[4][1],opt[4][2],opt[4][3]);
- drawRect(opt[5][0],opt[5][1],opt[5][2],opt[5][3]);
- }
Advertisement
Add Comment
Please, Sign In to add comment