Reading an input C++

Hi all,

I have a project which requires me to write a program to read a value of LED status on a microprocessor board using C++. I understand how to input a value from a keyboard using cin and using arguments to set a value but I am unsure how to get an input from a microprocessor which is connected via USB (portB).
I was wondering which commands would be the best to accomplish this??
closed account (48T7M4Gy)
This might help if you have an Arduino Uno or similar.

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
const int ledPin = 9; // to allow PWM if equired

char command;

void setup()
{
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
}

void loop()
{
  if (Serial.available() > 0)
{
    command = Serial.read();

    Serial.print("R: ");
    Serial.print(command);
  }

  switch ( toUpperCase(command) )
  {
    case '1':
      on();
      break;
    case '0':
      off();
      break;
    case 'F':
      flash();
      break;
    default:
      // statements
      break;
  }
 
}

void on()
{
  digitalWrite(ledPin, HIGH);
  return;
}

void off()
{
  digitalWrite(ledPin, LOW);
  return;
}

void flash()
{
  digitalWrite(ledPin, HIGH);
  delay(100);
  digitalWrite(ledPin, LOW);
  delay(50);
  return;
}
Topic archived. No new replies allowed.