Need advice to for school project..

how do i Develop an HMI video interface using the connected PC. The input can be the PC keyboard to enter numbers. Develop a program that prompts for the entry of five numbers (range -32768 to +32768 minimum) and the program calculates an average value as the result. A reset is required to clear and start the next cycle.

Not sure what "HMI video" is, perhaps you meant HDMI? You'll be wanting a Raspberry Pi, not an Arduino, for HDMI.

(range -32768 to +32768 minimum)

Either very sneaky, or a teacher who isn’t as clever as s/he thinks. :stuck_out_tongue_closed_eyes:

Hi, HMI Human Machine Interface, ie, the bit that lets you talk to the computer, controller.

Tom.... :)

that is what is said in the assignment. i still can't figure what to do!! help!!

Your hmi = serial monitor in this case. Job done!

Mark

yeah I figured it was the PC serial monitor but I can’t figure the coding part. That’s my main problem. not the monitor. I already figure that one. All the codes I’ve tried doesn’t work!!

joeadjei: yeah I figured it was the PC serial monitor but I can't figure the coding part. That's my main problem. not the monitor. I already figure that one. All the codes I've tried doesn't work!!

How do you expect to do a specific series of operations by using code you find on the net? Let's see. Flash a series of LEDs. No, that didn't average the 5 numbers. Hmm.. How about Find the level of liquid in an aquarium? No,, that didn't work either.

Show us some code. Tell us what you tried. Tell us what made you think it wasn't working? Show us some effort.

First of, I am new to arduino board and I find it interesting but at the same time, I am also new to coding. I am taking C++ and C courses right at this moment but I feel like this is another form. Here’s the code I tried for this project.

int enternumber;
int num1, num2, num3, num4, num5;
long answer=0;
boolean myswitch = false;

void setup(){
Serial.begin(9600);
num1 = 0;
num2 = 0;
num3 = 0;
num4 = 0;
num5 = 0;

}

void loop () {
while (Serial.available()){
enternumber = Serial.read();
Serial.write(enternumber);
if (enternumber > 47 && enternumber < 58){
if (!myswitch){
num1=(num110)+(enternumber-48);
}else{
num2=(num2
10)+(enternumber-48);
if (!myswitch){
num3=(num310)+(enternumber-48);
}else{
num4=(num4
10)+(enternumber-48);
if (!myswitch){
num5=(num5*10)+(enternumber-48);
}
}
}
}
if (enternumber == 61){
answer=num1+num2+num3+num4+num5;
Serial.print(num1);
Serial.print("+");
Serial.print(num2);
Serial.print("+");
Serial.print(num3);
Serial.print("+");
Serial.print(num4);
Serial.print("+");
Serial.print(num5);
Serial.print("=");
Serial.println(answer);

}
}
}

  num1 = 0;
  num2 = 0;
  num3 = 0;
  num4 = 0;
  num5 = 0;

By the time “setup()” runs, they’re already zero, but you may want to reset them in “loop()” after you’ve printed the value entered.

if (enternumber > 47 && enternumber < 58){

Don’t you think if (enternumber >= '0' && enternumber <= '9'){ is much easier to read?

After the fix. without the average yet. Just trying to see if the addition works.. I entered 1+1+1+1+1 to see if i will get 5. This is what I get on the serial monitor 1+1+1+1+1=1+1111+0+1111+0=2223

I went ahead and did some changes around but still not working the way i want it to.

int enternumber;
int num1, num2, num3, num4, num5;
long answer=0;
boolean myswitch = false;

void setup(){
Serial.begin(9600);
num1 = 0;
num2 = 0;
num3 = 0;
num4 = 0;
num5 = 0;

}

void loop () {
while (Serial.available()){
enternumber = Serial.read();
Serial.write(enternumber);
if (enternumber > ‘0’ && enternumber < ‘9’){
if (!myswitch){
num1=(num110)+(enternumber-48);
num2=(num2
10)+(enternumber-48);
num3=(num310)+(enternumber-48);
num4=(num4
10)+(enternumber-48);
}else{
num5=(num5*10)+(enternumber-48);
}
}

if (enternumber == 61){
answer=num1+num2+num3+num4+num5;
Serial.print(num1);
Serial.print("+");
Serial.print(num2);
Serial.print("+");
Serial.print(num3);
Serial.print("+");
Serial.print(num4);
Serial.print("+");
Serial.print(num5);
Serial.print("=");
Serial.println(answer);

num1=0;
num2=0;
num3=0;
num4=0;
num5=0;
myswitch=false;

}else if (enternumber ==43){
myswitch=true;
}
}
}

 if (enternumber > '0' && enternumber < '9'){

So, only digits 1 to 8.
Is that by design?

void setup(){
  Serial.begin(9600);
  num1 = 0;
  num2 = 0;
  num3 = 0;
  num4 = 0;
  num5 = 0;
  
}

They’re already all zero by the time setup() runs.
I think I’ve mentioned this.

You may want to think about how many times loop() runs in the time it takes to transmit a single character via serial.

Have a look at Nick Gammon’s excellent Serial tutorial at Gammon Forum : Electronics : Microprocessors : How to process incoming serial data without blocking