Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Code compiles and board connects, but no dice :(( (Read 1053 times)
sheeda
Newbies
*
Offline


Posts: 3
Joined: Mar 2nd, 2021
Code compiles and board connects, but no dice :((
Mar 3rd, 2021 at 3:52am
Print Post  
Hi,

I wrote some simple code to make sure everything was running correctly. I am using an Arduino Wifi Rev 2 board and everything shows up correctly (port, board, etc). The problem is every time I compile and run, no calculations are actually performed. The input will be requested, but no matter what I put in, I get zero. I've tried the code in Arduino IDE and Tinkercad and it works as intended there, but I love VS and would like to do my coding there. I've tried changing the code, I'm not sure what else to do. I've attached the code below. Thanks in advance!
-- a sad/hungryEEstudent

Code (C++)
Select All
/*
 Name:		one.ino
 Created:	3/2/2021 12:09:54 AM
 Author:	Rashidat
*/
#include <SoftwareSerial.h>
#include <stdio.h>
// the setup function runs once when you press reset or power the board
float a, ans;
int b, j;

void setup() {
	Serial.begin(9600);
}

// the loop function runs over and over again until power down or reset
void loop() {

	Serial.println("What is a?");
	while (Serial.available() == 0);
		a = Serial.parseFloat();

	Serial.println("What is b?");
	while (Serial.available() == 0);
		b = Serial.parseInt();
	Serial.println();

	int ans = 0;
	int j = 0;
	if (j <= b)
	{
		for (j < b; j++;)
		{
			ans = ans + a;
		}

	}
	Serial.print("The product is ");
	Serial.println(ans);
	delay(1000);
}
 

« Last Edit: Mar 3rd, 2021 at 11:36pm by sheeda »  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2174
Joined: Feb 13th, 2019
Re: Code compiles and oard connects, but no dice :((
Reply #1 - Mar 3rd, 2021 at 10:51am
Print Post  
Thanks for the report.

We have run this on a different board, however always get 0 in the Arduino IDE as well as Visual Micro (with both Serial monitors set to "No Line ending" so they match)

The issue seems to be how the for loop has been declared, as it has 2 of 3 parameters, and the increment/decrement parameter is empty.
e.g. change 
Code
Select All
for (j < b; j++;) 



to 
Code
Select All
for (j; j < b; j++) 



Now it should work as expected in all IDEs.
  
Back to top
 
IP Logged
 
sheeda
Newbies
*
Offline


Posts: 3
Joined: Mar 2nd, 2021
Re: Code compiles and oard connects, but no dice :((
Reply #2 - Mar 3rd, 2021 at 8:24pm
Print Post  
I actually tried doing that first, and I was still getting 0. Maybe I'm missing something in VS settings?
  
Back to top
 
IP Logged
 
sheeda
Newbies
*
Offline


Posts: 3
Joined: Mar 2nd, 2021
Re: Code compiles and oard connects, but no dice :((
Reply #3 - Mar 3rd, 2021 at 11:35pm
Print Post  
I also added two lines of code to spit out the values declared for a and b, so now I'm wondering if there's a problem with my board or USB cable? Either that, or there's something I'm missing using Serial.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Code compiles and board connects, but no dice :((
Reply #4 - Mar 7th, 2021 at 1:48am
Print Post  
I have corrected your code and posted it here. When you tested using the Arduino IDE you will have been using slightly different code because the code you posted was not valid.

Code (C++)
Select All
/*
 Name:		one.ino
 Created:	3/2/2021 12:09:54 AM
 Author:	Rashidat
*/
#include <SoftwareSerial.h>
#include <stdio.h>
// the setup function runs once when you press reset or power the board
float a, ans;
int b, j;

void setup() {
	while(!Serial)
	{ }

	Serial.begin(9600);
}

// the loop function runs over and over again until power down or reset
void loop() {

	Serial.println("What is a?");

	while (Serial.available() == 0) {};

	a = Serial.parseFloat();

	Serial.println("a: ");
	Serial.println(a);

	Serial.println("What is b?");

	while (Serial.available() == 0) {};

	b = Serial.parseInt();

	Serial.println("b: ");
	Serial.println(b);

	int ans = 0;
	int j = 0;
	if (j <= b)
	{
		Serial.println("j is less than b");

		for (j;j < b; j++)
		{
			ans = ans + a;
		}

	}

	Serial.print("The product is ");
	Serial.println(ans);
	delay(1000);
} 



tip: Your code does not use the SoftwareSerial library, that include is not required but is doing no harm.
« Last Edit: Mar 7th, 2021 at 2:02am by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint