Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <nokia_5110_lcd.h>
- #define MODE_SWITCH 5
- #define BLINK_BUTTON 6
- #define CLEAR_BUTTON 7
- #define XPIN A0
- #define YPIN A1
- const double XCON = .082;
- const double YCON = .046;
- #define WIDTH 83
- #define HEIGHT 47
- volatile int mode = PIXEL_ON;
- volatile boolean blinkFlag = false;
- //LCD PINS
- #define LCD_PWR 10
- #define LCD_SCE 9
- #define LCD_RESET 8
- #define LCD_DC 4
- Nokia_5110_lcd lcd(LCD_PWR, LCD_DC, LCD_SCE, LCD_RESET);
- void setup()
- {
- Serial.begin (9600);
- Serial.println("Start");
- lcd.init(100); //parameter is contrast value, between 0 [low] and 127 [high]
- lcd.clear();
- pinMode(MODE_SWITCH, INPUT_PULLUP);
- pinMode(BLINK_BUTTON, INPUT_PULLUP);
- pinMode(CLEAR_BUTTON, INPUT_PULLUP);
- attachInterrupt(0, toggleMode, CHANGE);
- attachInterrupt(1, flagBlink, CHANGE);
- attachInterrupt(2, clear, CHANGE);
- toggleMode();
- }
- /* loop */
- void loop(){
- int x = analogRead(XPIN)*XCON;
- int y = analogRead(YPIN)*YCON;
- //Serial.println("X: " + (String)x);
- //Serial.println("Y: " + (String)y);
- if(blinkFlag){
- blinkCursor(x,y);
- }
- lcd.setPixel(x, y, mode);
- }
- void toggleMode() {
- Serial.println(digitalRead(MODE_SWITCH));
- if(digitalRead(MODE_SWITCH) == LOW){
- mode = PIXEL_ON;
- }
- else {
- mode = PIXEL_OFF;
- }
- }
- void blinkCursor(int x, int y){
- Serial.println("BLINKING");
- for(int i = 0; i < 8; i++){
- if(i % 2 == 0){
- lcd.setPixel(x, y, PIXEL_ON);
- }
- else {
- lcd.setPixel(x, y, PIXEL_OFF);
- }
- delay(250);
- }
- lcd.setPixel(x, y, mode);
- blinkFlag = false;
- }
- void flagBlink(){
- if(digitalRead(BLINK_BUTTON) == LOW){
- Serial.println("flagBlink()");
- blinkFlag = true;
- }
- }
- void clear(){
- if(digitalRead(CLEAR_BUTTON) == LOW){
- lcd.clear();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment