amal915
September 23, 2022, 9:54pm
1
Im using Digispark ATTiny85 with 128x32 OLED display and I want to scroll my text up and down with 2 buttons. Im using Tiny4kOLED library and don't really know what should i do to get it to work as I want.
This is my code:
#include <Tiny4kOLED.h>
#define OG 1
#define OD 4
unsigned int i = 1;
void setup() {
pinMode(OG,INPUT);
pinMode(OD,INPUT);
}
void loop() {
if(millis() == 200){
oled.begin();
oled.setRotation(0);
oled.setFont(FONT6X8);
oled.clear();
}
oled.setCursor(0,0);
oled.print("TEXT");
if(digitalRead(OG) == HIGH && digitalRead(OD) == HIGH) {delay(150); i++;}
if(i%2 == 0) {
oled.on();
}
if(i%2 == 1) {
oled.off();
}
if(digitalRead(OD) == HIGH && digitalRead(OG) == LOW){
oled.scrollLeftOffset(7,1,7,1);
oled.setVerticalScrollArea(11, 50);
oled.activateScroll();
}
if(digitalRead(OD) == LOW){
oled.scrollLeftOffset(0,0,0,0);
oled.setVerticalScrollArea(11, 50);
}
}
OG and OD are P1 and P4 pins on board and theyre getting read as they should. After connecting OD to 5v text is moving downwards but strange dots starts showing up and when its released text is not stoping in the postion it was but it goes all the way to the top.
b707
September 23, 2022, 10:12pm
3
add to last code block in the loop():
oled.deactivateScroll();
You can always find all library command in library source code.
amal915
September 23, 2022, 10:43pm
4
It seems like oled.deactivateScroll
exists in library but it don't stop in the middle of text. It still goes to start.
b707
September 23, 2022, 10:44pm
5
please show your code with this line inserted.
amal915
September 23, 2022, 10:45pm
6
void loop() {
if(millis() == 200){
oled.begin();
oled.setRotation(0);
oled.setFont(FONT6X8);
oled.clear();
}
oled.setCursor(0,0);
oled.print("Text");
if(digitalRead(OG) == HIGH && digitalRead(OD) == HIGH) {delay(300); i++;}
if(i%2 == 0) {
oled.on();
}
if(i%2 == 1) {
oled.off();
}
if(digitalRead(OD) == HIGH && digitalRead(OG) == LOW){
oled.scrollLeftOffset(7,1,8,1);
oled.setVerticalScrollArea(0, 200);
oled.activateScroll();
}
if(digitalRead(OD) == LOW){
oled.scrollLeftOffset(0,0,0,0);
oled.setVerticalScrollArea(0, 10);
oled.deactivateScroll();
}
}
Also i tried without Offset and Scroll Area
b707
September 23, 2022, 10:47pm
7
Please show how your OD and OG knobs are connected. Do you use pullup or pulldown?
amal915
September 23, 2022, 10:48pm
8
I just connect 5v to pin without any resistors
b707
September 23, 2022, 10:50pm
9
try adding the resistor 2K-10K between OD and GND.
PS I don't know how the `oled.deactivateScroll() should work. Perhaps it do not just stop the scroll, but return the text to start position....
amal915
September 23, 2022, 11:03pm
12
I soldered 10K resistor between gnd and OD but nothing changed
b707
September 23, 2022, 11:05pm
13
try to comment these Offset and ScrollArea lines:
amal915:
if(digitalRead(OD) == LOW){
//oled.scrollLeftOffset(0,0,0,0);
//oled.setVerticalScrollArea(0, 10);
oled.deactivateScroll();
}
If this won't help - no more ideas, sorry
system
Closed
March 22, 2023, 11:11pm
16
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.