Blinking and color

The output at the way bottom, there are a bunch of outputs I need them in color and blinking. When it says ON the color should be yellow and When it is OFF color should be white. When it says blinking it should be blinking. Please don't tell me what to do, people told me i tried it did not work, i need someone else to do it for me.

Thanks

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
#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <windows.h>

using namespace std;
/* prototype (function typedef) for DLL function Oup32fp: */

     typedef void (_stdcall *oupfuncPtr)(short portaddr, short datum);

#define PPORT_BASE 0x378 // identify port address

// After successful initialization, this variable will contain function pointer.
     oupfuncPtr oup32fp;

// Wrapper function for the function pointer - call these functions to perform I/O.

     void  Out32 (short portaddr, short datum)
     {
          (oup32fp)(portaddr,datum);
     }

HINSTANCE hLib;

int initialize()
{
     /* Load the library */
     hLib = LoadLibrary("inpout32.dll");
     if (hLib == NULL) {
          fprintf(stderr,"LoadLibrary Failed.\n");
          getch();
          return -1;
                      }
    /* get the address of the function */
     oup32fp = (oupfuncPtr) GetProcAddress(hLib, "Out32");

     if (oup32fp == NULL) {
          fprintf(stderr,"GetProcAddress for Oup32 Failed.\n");
          getch();
          return -1;
     }
     return 0;
}
// ---------------- DO NOT CHANGE ANY OF THE ABOVE CODE --------------------------

int main()
{
     short value; // smaller integer type for port data
     int port = PPORT_BASE; // memory address for parallel port
     initialize(); // call function to set up port for output

     for (int counter = 1; counter <= 5; counter ++)
     {
         Out32(port,9);// Turn North/South GREEN & Hold WEST/EAST RED
         cout << "---North & South = ON          East & West = OFF---\n";
         Sleep(3000);// Holds Green Light for 3 sec

         Out32(port,4);// WEST/EAST  RED and NORTH/SOUTH YELLOW
         cout << "---North & South = BLINKING         East & West = OFF---\n";
         Sleep(1000);//Holds YELLOW NORTH/SOUTH

         Out32(port,3); // Turn all light RED
         cout << "---North & South = OFF            East & West = OFF---\n";
         Sleep(500); // Hold RED half sec

         Out32(port,34);// Turn EAST/ WESTGREEN GREEB AND NORTH/SOUTH RED
         cout << "---North & South = OFF            East & West = ON---\n";
         Sleep(3000);// Holds Green Light for 3 sec

         Out32(port,18);// Turns all lights RED and EAST/WEST YELLOW
         cout << "---North & South = OFF            East & West = BLINKING---\n";
         Sleep(2000);//Holds YELLOW EAST/WEST

         Out32(port,3); // Turn all light RED
         cout << "---North & South = OFF            East & West = OFF---\n";
         cout << "" << endl;
         cout << "Times ran = " << counter << endl;
         Sleep(500); // Hold RED half sec
     }


     FreeLibrary(hLib);
     cout << endl;
     system("PAUSE");
     return(0);
}
What is the Out32 function you're importing and how does it work?
Out 32 is an output function. In this case I programmed a cross walk to turn on and off in a certain amount of time. This is how traffic lights and cross walks etc are programmed. I just need to know how to do da color and blinking!!!
Last edited on
Out 32 is an output function


You'll have to be more specific.

What are the parameters you're passing it do? What is the difference between Out32(port,34); and Out32(port,18);?

If you want to change the behavior of the output (ie: change color, have it blink) then you need to understand how this function works and how to use it. If you don't provide us with details/documentation about that function there is nothing we can do to help.
It does not matter about ports. In the program i just have to replicate it to show what is happening. the out 32 is all good, but i just need to change the color of the cout.

Like here

Out32(port,9);// Turn North/South GREEN & Hold WEST/EAST RED
cout << "---North & South = ON East & West = OFF---\n";
Sleep(3000);// Holds Green Light for 3 sec

I need to change ON in to yellow and OFF can stay white. If it blinking it should be obviously blinking.

and the ports are where the signal is going to. when i connect to a circuit, there are differant lights to be turned on at differant times, so you need differant ports
Last edited on
Oh okay.. so you want the cout text to be blinking... not the traffic lights?
For color, you could look at SetConsoleTextAttribute:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms686047%28v=vs.85%29.aspx

For the blinking, you could consider SetConsoleCursorPosition and continually overwriting the text with spaces and then redisplaying it.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms686025%28v=vs.85%29.aspx
For the blinking, you could even use SetConsoleTextAttribute to set the colour of the section to black on black, and then back to whatever colours you want. You'll probably want to split up the text, though: That way you can make it easier to get the end positions of the text (through strlen or something).
Topic archived. No new replies allowed.