C/Visual C - Desplazamiento de derecha a izquierda de un display led en c++

 
Vista:
Imágen de perfil de Giancarlo

Desplazamiento de derecha a izquierda de un display led en c++

Publicado por Giancarlo (5 intervenciones) el 11/12/2015 05:00:06
Les dejo el código aquí. Costo muchísimo armarlo quizás me he perdido algunas cosas pero en ese caso comenten, su consulta no molesta estamos aqui para ayudarnos y tengo un problema..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
#include <vcl.h>
#pragma hdrstop
 
#include "UnitLEDDISPLAY.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
bool empezar = false; //para el reproductor de mp3
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void TForm1::BorrarDisplay(){
DisplayLed->Canvas->Brush->Color=FDisplayBackColor;
DisplayLed->Canvas->FillRect(DisplayLed->Canvas->ClipRect);
DisplayLed->Canvas->Brush->Color=FLedOffColor;
DisplayLed->Canvas->Pen->Color=FLedBorderOffColor;
for(int i=0;i<64;i++){
    for(int j=0;j<16;j++){
        DisplayLed->Canvas->Ellipse(FBorderWidth+i*(FLedSize+FLedSpace),
                                    FBorderWidth+j*(FLedSize+FLedSpace),
                                    FBorderWidth+i*(FLedSize+FLedSpace)+FLedSize,
                                    FBorderWidth+j*(FLedSize+FLedSpace)+FLedSize);
    }
}
PaintBox1->Canvas->Draw(0,0,DisplayLed);
}
//---------------------------------------------------------------------------
void TForm1::DibujarPantalla(int Screen, int FromLedX, int FromLedY, int ToLedX, int ToLedY){
TColor ledon,ledborder;
DisplayLed->Canvas->Brush->Color=FDisplayBackColor;
DisplayLed->Canvas->FillRect(DisplayLed->Canvas->ClipRect);
 
DisplayLed->Canvas->Brush->Color=clAqua;
DisplayLed->Canvas->Pen->Color=clAqua;
DisplayLed->Canvas->Rectangle(FBorderWidth+LastSelectedX*(FLedSize+FLedSpace),
                              FBorderWidth+LastSelectedY*(FLedSize+FLedSpace),
                              FBorderWidth+LastSelectedX*(FLedSize+FLedSpace)+FLedSize,
                              FBorderWidth+LastSelectedY*(FLedSize+FLedSpace)+FLedSize);
for(int i=FromLedX;i<ToLedX;i++){
    for(int j=FromLedY;j<ToLedY;j++){
        switch(screens[Screen].screen[i][j]){
        case 0:
            ledon=FLedOffColor;
            ledborder=FLedBorderOffColor;
        break;
        case 1:
            ledon=clRed;
            ledborder=clMaroon;
        break;
        case 2:
            ledon=clLime;
            ledborder=clGreen;
        break;
        case 3:
            ledon=clYellow;
            ledborder=clOlive;
        break;
        }
        DisplayLed->Canvas->Brush->Color=ledon;
        DisplayLed->Canvas->Pen->Color=ledborder;
        DisplayLed->Canvas->Ellipse(FBorderWidth+i*(FLedSize+FLedSpace),
                                    FBorderWidth+j*(FLedSize+FLedSpace),
                                    FBorderWidth+i*(FLedSize+FLedSpace)+FLedSize,
                                    FBorderWidth+j*(FLedSize+FLedSpace)+FLedSize);
    }
}
PaintBox1->Canvas->Draw(0,0,DisplayLed);
}
//---------------------------------------------------------------------------
void TForm1::BorrarPantalla(int Screen){
int nscreens;
 
nscreens=1;
if(Screen<=0 || Screen>120)
    nscreens=120;
for(int i=0;i<nscreens;i++){
    for(int x=0;x<64;x++){
        for(int y=0;y<16;y++){
            screens[i].screen[x][y]=0;
        }
    }
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
DisplayLed=new Graphics::TBitmap();
FBorderWidth=5;
FLedSpace=2;
FLedSize=10;
FDisplayBackColor=clBlack;
FLedOffColor=TColor(0x00363636);
FLedBorderOffColor=TColor(0x00272727);
DisplayLed->Width=2*FBorderWidth+64*FLedSize+63*FLedSpace;
DisplayLed->Height=2*FBorderWidth+16*FLedSize+15*FLedSpace;
PaintBox1->Width=DisplayLed->Width;
PaintBox1->Height=DisplayLed->Height;
for(int i=0;i<120;i++){
    for(int x=0;x<64;x++){
        for(int y=0;y<16;y++)
            screens[i].screen[x][y]=0;
    }
}
BorrarDisplay();
FLedOnColor=clRed;
FLedBorderOnColor=clMaroon;
Memo1->Clear();
 
ProgressBar1->Position=0; //para la posicion de la barra de progreso en el mp3
}
//---------------------------------------------------------------------------
 
void __fastcall TForm1::PaintBox1Paint(TObject *Sender)
{
if(!first)
    PaintBox1->Canvas->Draw(0,0,DisplayLed);
first=true;
}
//---------------------------------------------------------------------------
 
void __fastcall TForm1::ScrollBar1Change(TObject *Sender)
{
DibujarPantalla(ScrollBar1->Position,0,0,64,16);
Label1->Caption=IntToStr(ScrollBar1->Position);
}
//---------------------------------------------------------------------------
 
void __fastcall TForm1::PaintBox1MouseMove(TObject *Sender,
      TShiftState Shift, int X, int Y)
{
int x,y;
 
x=(X-FBorderWidth)/(FLedSize+FLedSpace);
y=(Y-FBorderWidth)/(FLedSize+FLedSpace);
oldX=x;
oldY=y;
if(Shift.Contains(ssLeft)){
    if(SpeedButton1->Down)
        screens[ScrollBar1->Position].screen[x][y]=1;
    if(SpeedButton2->Down)
        screens[ScrollBar1->Position].screen[x][y]=2;
    if(SpeedButton3->Down)
        screens[ScrollBar1->Position].screen[x][y]=3;
    DibujarPantalla(ScrollBar1->Position,0,0,64,16);
}
if(Shift.Contains(ssRight)){
    screens[ScrollBar1->Position].screen[x][y]=0;
    DibujarPantalla(ScrollBar1->Position,0,0,64,16);
}
}
//---------------------------------------------------------------------------
 
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
if(SpeedButton1->Down)
    Edit1->Font->Color=clRed;
if(SpeedButton2->Down)
    Edit1->Font->Color=clLime;
if(SpeedButton3->Down)
    Edit1->Font->Color=clYellow;
}
//---------------------------------------------------------------------------
 
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(FontDialog1->Execute()){
    Edit1->Font->Name=FontDialog1->Font->Name;
    Button1->Caption="FUENTE - "+IntToStr(FontDialog1->Font->Size);
    Edit1->Font->Style=FontDialog1->Font->Style;
}
}
//---------------------------------------------------------------------------
 
void __fastcall TForm1::Button2Click(TObject *Sender)
{
AnsiString str;
Graphics::TBitmap *auxtext=new Graphics::TBitmap();
int p;
 
str=Edit1->Text;
auxtext->Canvas->Font=FontDialog1->Font;
auxtext->Canvas->Font->Color=Edit1->Font->Color;
auxtext->Width=auxtext->Canvas->TextWidth(str)+5;
auxtext->Height=auxtext->Canvas->TextHeight(str);
auxtext->Canvas->Brush->Color=clBlack;
auxtext->Canvas->FillRect(auxtext->Canvas->ClipRect);
auxtext->Canvas->TextOut(0,0,str);
 
p=ScrollBar1->Position;
for(int i=0;i<auxtext->Width;i++){
    for(int j=0;j<16;j++){
        if(auxtext->Canvas->Pixels[i][j]==clBlack)
            screens[p+i/64].screen[i%64][j]=0;
        if(auxtext->Canvas->Pixels[i][j]==clRed)
            screens[p+i/64].screen[i%64][j]=1;
        if(auxtext->Canvas->Pixels[i][j]==clLime)
            screens[p+i/64].screen[i%64][j]=2;
        if(auxtext->Canvas->Pixels[i][j]==clYellow)
            screens[p+i/64].screen[i%64][j]=3;
    }
}
ScrollBar1->Position=p+auxtext->Width/64;
DibujarPantalla(ScrollBar1->Position,0,0,64,16);
}
//---------------------------------------------------------------------------
 
void __fastcall TForm1::PaintBox1DblClick(TObject *Sender)
{
LastSelectedX=oldX;
LastSelectedY=oldY;
DibujarPantalla(ScrollBar1->Position,0,0,64,16);
}
//---------------------------------------------------------------------------
 
void __fastcall TForm1::Button4Click(TObject *Sender)
{
AnsiString str;
int p;
 
str="";
if(InputQuery("Funcion MOSTRAR PANTALLA","Pantalla",str)){
    p=StrToIntDef(str,-1);
    if(p>=0 && p<120)
        Memo1->Lines->Add("F01;"+IntToStr(p));
    else
        ShowMessage("Pantalla ERROR");
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button6Click(TObject *Sender)
{
AnsiString str;
int p;
 
str="";
if(InputQuery("Funcion ESPERAR","SEGUNDOS",str)){
    p=StrToIntDef(str,-1);
    if(p>=0)
        Memo1->Lines->Add("F02;"+IntToStr(p));
    else{
        ShowMessage("Funcion ERROR");
        }
    }
}
//---------------------------------------------------------------------------
 
void __fastcall TForm1::Button5Click(TObject *Sender)
{
AnsiString str;
int pi,pf,intervalo;
 
str="";
if(InputQuery("Funcion ANIMAR","Pantalla INCIO",str)){
    pi=StrToIntDef(str,-1);
    if(pi<0 || pi>119){
        ShowMessage("Pantalla ERROR");
        return;
    }
}
else
    return;
str="";
if(InputQuery("Funcion ANIMAR","Pantalla FINAL",str)){
    pf=StrToIntDef(str,-1);
    if(pf<0 || pf>119 || pf<pi){
        ShowMessage("Pantalla ERROR");
        return;
    }
}
else
    return;
str="";
if(InputQuery("Funcion ANIMAR","INTERVAL Animacion [ms*10]",str)){
    intervalo=StrToIntDef(str,-1);
    if(intervalo<=0){
        ShowMessage("Pantalla ERROR");
        return;
    }
}
else
    return;
Memo1->Lines->Add("F03;"+IntToStr(pi)+";"+IntToStr(pf)+";"+IntToStr(intervalo));
 
}
//---------------------------------------------------------------------------
 
void __fastcall TForm1::Button3Click(TObject *Sender)
{
if(Button3->Caption=="START"){
    if(Memo1->Lines->Count==0)
        return;
    linea_programa=0;
    Button3->Caption="STOP";
    Timer1->Enabled=true;
}
else{
    Timer1->Enabled=false;
    Button3->Caption="START";
}
}
//---------------------------------------------------------------------------
 
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
unsigned char funcion;
int i,parametro1,parametro2,parametro3;
AnsiString str,straux;
 
if(esperando){
    ms_a_esperar--;
    if(ms_a_esperar==0)
        esperando=false;
    return;
}
 
str=Memo1->Lines->Strings[linea_programa];
 
funcion=StrToInt(str.SubString(2,2));
switch(funcion){
    case 1://Funcion Mostrar Pantalla
        parametro1=StrToInt(str.SubString(5,str.Length()-4));
        DibujarPantalla(parametro1,0,0,64,16);
    break;
    case 2://Esperar
        parametro1=StrToInt(str.SubString(5,str.Length()-4));
        ms_a_esperar=parametro1*100;
        esperando=true;
    break;
    case 3://Animar
        i=4;
        straux=AnsiString(str.c_str()[i]);
        for(i=5;i<str.Length();i++){
            if(str.c_str()[i]==';'){
                parametro1=StrToInt(straux);
                i++;
                break;
             }
             else
                straux=straux+AnsiString(str.c_str()[i]);
        }
        straux=AnsiString(str.c_str()[i++]);
        for(;i<str.Length();i++){
            if(str.c_str()[i]==';'){
                parametro2=StrToInt(straux);
                i++;
                break;
             }
             else
                straux=straux+AnsiString(str.c_str()[i]);
        }
        straux=AnsiString(str.c_str()[i++]);
        for(;i<str.Length();i++)
            straux=straux+AnsiString(str.c_str()[i]);
        parametro3=StrToInt(straux);
 
        if(!primer_parametro){
            pantalla_a_mostrar=parametro1-1;
            primer_parametro=true;
        }
        pantalla_a_mostrar++;
        if(pantalla_a_mostrar!=parametro2){
            linea_programa--;
            ms_a_esperar=parametro3;
            esperando=true;
        }
        else
            primer_parametro=false;
        DibujarPantalla(pantalla_a_mostrar,0,0,64,16);
    break;
}
 
linea_programa++;
if(linea_programa==Memo1->Lines->Count)
    linea_programa=0;
}
//---------------------------------------------------------------------------
 
void __fastcall TForm1::Button7Click(TObject *Sender)
{
AnsiString str;
 
if(Memo1->Lines->Count==0)
    return;
if(SaveDialog1->Execute()){
    Memo1->Lines->SaveToFile(SaveDialog1->FileName);
    str=SaveDialog1->FileName.SubString(1,SaveDialog1->FileName.Pos(".")-1);
    str=str+".pr1";
    TFileStream *archivo=new TFileStream(str,fmCreate);
    for(int i=0;i<120;i++){
        archivo->Write(&screens[i],sizeof(struct screenbase));
    delete archivo;
    }
    }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button12Click(TObject *Sender)
{
AnsiString str;
 
if(OpenDialog1->Execute()){
    Memo1->Lines->LoadFromFile(OpenDialog1->FileName);
    str=OpenDialog1->FileName.SubString(1,OpenDialog1->FileName.Pos(".")-1);
    str=str+".pr1";
    TFileStream *archivo=new TFileStream(str,fmOpenRead);
    for(int i=0;i<120;i++){
        archivo->Read(&screens[i],sizeof(struct screenbase));
        DibujarPantalla(i,0,0,64,16);
    }
    ScrollBar1->Position=0;
    DibujarPantalla(0,0,0,64,16);
    delete archivo;
 
}
}




LO QUE QUIERO ES DESPLAZAR LA PANTALLA COMPLETA CON LO QUE TENGA ESCRITO EN ESE MOMENTO TANTO A LA DERECHA COMO A LA IZQUIERDA... Alguna sugerencia?
Si quieren despues les paso el codigo completo con el formulario y todo.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 296
Bronce
Ha mantenido su posición en C/Visual C (en relación al último mes)
Gráfica de C/Visual C

Desplazamiento de derecha a izquierda de un display led en c++

Publicado por agustin (272 intervenciones) el 11/12/2015 09:46:31
Amigo yo hice algo así y saludos solución fue usar un array bidimensional el cual contenía los "leds" tal como se mostrarían en pantalla y lo ordenaba como deseaba y luego lo mostraba por pantalla.
Te paso mi proyecto para que veas como lo hice a ver si te da ideas: https://mega.co.nz/#!Nw8QwLIA!lz0cnP6cLRa5NQjJ31CZC_sHA1jljSI_hYWDmidYdoI
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar