/*TFT_Grap.ino Arduining 7 AUG 2016
*/
#include <TFT.h>
#include <SPI.h>
//pin definitions:
#define CS 10
#define DC 9
#define RST 8
#define BKLIGHT 6 // Backlight control pin
#define BRIGHTNESS 204 // Backlight intensity (0-255)
#define RANGE 100 // Vertical size of the graph in pixels.
#define WIDTH 128 // Horizontal size of Display in pixels.
#define HEIGHT 160 // Vertical size of Display in pixels.
#define PERSIST 500 // persistence of the graph (milliseconds).
TFT TFTscreen = TFT(CS, DC, RST);
int value ;
int last_value;
int x_pos= 0; // cursor position
int offset= 40; // vertical graph displacement in pixels.
void setup(){
TFTscreen.begin(); // initialize the display
TFTscreen.setRotation(0);
TFTscreen.background(0,128,0); // dark green background
TFTscreen.stroke(255,255,255); // white stroke
analogWrite(BKLIGHT,BRIGHTNESS); //Set brightness.
TFTscreen.setTextSize(1);
TFTscreen.text("Oscilloscope",50,151);
drawFrame();
clearGraph();
}
void drawFrame(){
TFTscreen.stroke(255,255,255); // white stroke
TFTscreen.fill( 255, 255, 255 ); // White fill
TFTscreen.rect(0, 0, WIDTH, 21);
TFTscreen.setTextSize(1);
TFTscreen.stroke(0,0,0); // black text
TFTscreen.text("Volts: 1.0V/Div",2,2); // Example text.
TFTscreen.text("Time: 10mS/Div",2,12); // Exanple text
}
void clearGraph(){
TFTscreen.stroke(127,127,127); // grey for the border
TFTscreen.fill( 180, 0, 0 ); // dark Blue for the background
TFTscreen.rect(0, 22, 128, 128);
TFTscreen.line(65, 23, 65, 151); // vertical line
TFTscreen.line(1, 85,127, 85); // horizontal line
TFTscreen.stroke(0,255,255); // yellow stroke for plotting.
}
void plotLine(int last,int actual){
if(x_pos==0)last= actual; // first value is a dot.
TFTscreen.line(x_pos-1, last, x_pos, actual); // draw line.
x_pos++;
if(x_pos > WIDTH){
x_pos=0;
delay(PERSIST);
clearGraph();
}
}
void loop(){
last_value= value;
value= analogRead(A0);
value= map(value,0,1023,149,23);
value -= offset;
if(value <= 23) value= 23; //truncate off screen values.
plotLine(last_value ,value );
delay(10);
}
Did you mean to post some text with that? Maybe an explanation or something? Or are you just going to plop one title, a diagram, and a piece of code and hope we just do the work for you?
Not even going to say "hi" or anything?
Hi my name is Nelson I am eleven years old and I am taiwanese.
I need to use botton to +/- ms/div
Where are those things, what do the look like. Nice useless picture but with nicely labeled colored lines. It sort of looks like a business card with a palm pilot. I looked for a TFT display and found thousands of them, several hundred matched your description. The best information I can give at this point is to swap the orange and brown with the green and yellow lines.
What is your question and where are the links to the technical information and a real annotated schematic? It might come as a surprise but I am not clairvoyant.
I use the:1.8 lcd tft st7735 , arduino NANO (Original),some good jump wire.
can everyone help me?
Your question lacks any details and you haven't told us much. Look around at the other threads that get a lot of answers and see how much those people write.
You need to explain what the problem is. You need to explain what you've tried and what the results were. You can't just say "I need this" and expect that someone will jump up and do it for you like they are your employee.
We will help but you have to put in some effort. At least put in the effort to describe your project.
@nil921922 I'll take a stab at interpreting your problem.
My XYZ LCD shows a graph with X axis being ms/div; I want to use buttons to increase or decrease that ms/div setting. How do I go about doing that?
If this is a correct interpretation, please indicate that so that others may move forward to help you. I'm leaving the forum for the day, shortly.
I need to use two push botton to +/- ms/div I just a rookie I don't know to more for arduino.
Why do you leaving the forum?
How many different +/-ms/div do you want? 10ms/div is coded into your program with:
Which, with longer divisions, (500ms/div?) might make it hard to detect a button press.
Which pins are you going to hook the buttons to?
I am sorry to say I feel you are not quite ready to start the project at this point. We have no idea of your skill set or what resources you have available to you. I would suggest you start with some of the tutorials that are on line, sorry to say some are not so good but many are very good. Start by learning
the basics, you will need to control outputs as well as interpret inputs such as reading a switch, receiving a message etc. Start with the LED, they are not expensive and there is even one on most of the Arduinos. At this point you should have also found several tutorials on basic electronics that you
have gone through. You should acquire a copy of the Arduino Cookbook and go through that. I have no clue as to how fast you will learn this but it will probably take a few weeks. You can also go on line at this link: https://www.youtube.com/c/CodeBeauty There is a lot of material in small bytes (bites).
During this process you will learn what an IDE is and how to use it to generate and upload your code to the Arduino. Let us know how you progress. For more help check this link: https://docs.arduino.cc/learn/starting-guide/getting-started-arduino/
Camsysca said “leaving the forum for the day.” They are not leaving permanently and will be back when they have time available for here. Their reason why is because their time management requires them to do something else for the remainder of the day.
I need 1us~1s ms/div.
botton on A0,A1.
The code you have uses pin A0 for the analog input. It is not possible to use one pin with multiple simultaneous inputs so one of your buttons must connect to a different input pin.
A1,A2 button.
Ok simple. Save your code somewhere and set it aside. Search this site for tutorials on buttons and switches. Try the "State Change Example" in the Arduino IDE. Look for tutorials about that. Take some time to try to understand how to connect and read from a button.
After you study this for a little while you will learn what you need to do to this code.
Perhaps Nelson has some sort of o'scope in mind.
PE - recalling XY Plotters we used a lot at my first job.
Have you tried those times by editing the code to use different delays for here:
You could try:
But I think you will have difficulties with the smaller intervals because plotting, etc, will take significant time, slowing the sampling rate.
Personally I'd use an array of structures to keep track of the times and their names:
struct TimeStruct {
uint32_t intervalUs;
char name [] ;
};
TimeStruct times[] = {
{1, "1us/div"},
{10000, "10ms/div"},
{1000000, "1s/div"}
};
const int NumTimes = sizeof(times) / sizeof(times[0]);
int timeIndex = 1;
Then if you can use the buttons to change timeIndex
as desired*
, you can use times[timeIndex].name
and times[timeIndex].intervalUs
where appropriate.
*
-- See https://docs.arduino.cc/built-in-examples/digital/StateChangeDetection/ per