C++ Microcontroller

Hi Guys,

Need your kind expert advice. I have to come out with a programme in C++ but I have no idea how to make it, really hope that anyone of you here can help me. the output is suppose to be as below. Pls guide me, experts. Thanks.

Led Pattern: 0 0 0 0 0 0 0 1
Enter logic states of sw1 and sw0, separated by a space: 0 1
Led Pattern: 1 0 0 0 0 0 0 0
Enter logic states of sw1 and sw0, separated by a space: 0 1
Led Pattern: 0 1 0 0 0 0 0 0
Enter logic states of sw1 and sw0, separated by a space: 0 1
Led Pattern: 0 0 1 0 0 0 0 0
Enter logic states of sw1 and sw0, separated by a space: 1 0
Led Pattern: 0 1 0 0 0 0 0 0
Enter logic states of sw1 and sw0, separated by a space: 1 0
Led Pattern: 1 0 0 0 0 0 0 0

I need to create 3 classes....switch class...led class...circuit class

appreciate for your advice people
That's funny because I have no idea how to make it either.
Do you have any other information you can give us on this incalculably vague assignment?
okie

basically how could we display all this 8 binary numbers?

when we input 01 the 8 binary o/p, the '1' will move to the right, if 10 it will move to the right
To the right and to the right?
OK, clarify even further. Give me the whole damn homework assignment because your descriptions so far are crap. I'll grin and bear it because I can't figure this out.
Looks like a shift operation to me. From from I can tell, if the first bit is 0, the bits are shifted to the right, otherwise they're shifted to the left. AFAICT, the second bit is meaningless.

Right?
In that case go STL bitset. It'll be quite simple to use.
if its 11 the binary will not change. it will stay as per the earlier position
What do you mean 11? You still haven't explained the whole assignment, or how input is interpreted, or what the HELL you're doing.
tummychow: If you can't understand, don't complain that it's not clearly explained. The explanation is incomplete, true, but it's not unintelligible. After all, I could figure it out, and I understand what "11" means.

rey: What about 00? Undefined?
Last edited on
the 00 input will also have no change from the previous pattern

tummychow: apology if i have confuse you. i just need help...nothing more than that..appreciate if u can help with the source code. i may not be able to further explain till some qns relate to me...appreciate for your understanding
here is example of bitshifting and displaying the binary output:


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

// example of bitshifting
#include <iostream>
using namespace std;
void show_binary(unsigned int u);

int main()
{
int i=1, t;

	// shift left
	for (t=0;t<8;t++)  {
		show_binary(i);
		i = i << 1;
	}

	cout << "\n";

	// shift right
	for (t=0;t<8;t++)  {
		i = i >> 1;
		show_binary(i);
	
	}

	return 0;

}

// DIsplay the bits within a byte.
void show_binary(unsigned int u)

{

	int t;
	for(t=128;t>0;t=t/2)
	if(u & t) cout << "1 ";
	else cout << "0 ";
	cout << "\n";
 
}





0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 0
0 0 0 0 0 1 0 0
0 0 0 0 1 0 0 0
0 0 0 1 0 0 0 0
0 0 1 0 0 0 0 0
0 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0

1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 1


Last edited on
thanks bro, but how o we prompt the user for the input in order to make it shift
This section of the tutorial covers basic input/output commands:
http://cplusplus.com/doc/tutorial/basic_io/
as far as making the output 'shift' other than the example above, study the bitwise operator section of this:
http://cplusplus.com/doc/tutorial/operators/

it would probably be a good move to get familiar with the tutorial in general, its a great reference
do we use for loop or the if else condition for this requirement?
Just out of curiosity, are you programming an actual microcontroller, or creating an 'emulation' program?

If the former, what microcontroller are you using?

If the latter, is this a precursor to actual microcontroller programming?
its just an emulation bro...any idea how to come out with the prompt to move it left or right?
Topic archived. No new replies allowed.