Go Down

Topic: Need help getting rid of code errors (Read 810 times) previous topic - next topic

Tonyodonnell01

May 02, 2012, 11:36 pm Last Edit: May 02, 2012, 11:47 pm by Tonyodonnell01 Reason: 1
You might have seen this code before and if you have could you see what is wrong with this code and help/give hints on how to get rid of these code errors and get it to compile?




Code: [Select]


// Initialize

int PWM1  = 6;  // PWM Pin Motor 1
int PoM1  = 7;  // Polarity Pin Motor 1
int PWM2  = 5;  // PWm Pin Motor 2
int PoM2  = 4;  // Polarity Pin Motor 2

int ValM1  = 0;  // Initial Value for PWM Motor 1
int ValM1  = 0;  // Initial Value for PWM Motor 2

int i = 25;  // increment
boolean goUp = true;  // Used to detect acceleration or deceleration


void setup()
{
 pinMode(PWM1,  OUTPUT);
 pinMode(PoM1,  OUTPUT);
 pinMode(PWM2, OUTPUT);
 pinMode(PoM2, OUTPUT);
 
 digitalWrite(PoM1, LOW);  // Both motors with the sam polarity
 digitalWrite(PoM2, LOW);
 
 analogWrite(PWM1, ValM1);  // Stops both motors => ValMx = 0
 analogWrite(PWM2, ValM2);  
 Serial.begin(9600);        // Used to check value
}

// Main program

void loop()
{
 delay (500);                 // Give time to theh motor to adapt to new value
 if ((ValM1 < 250) && goUp)  // First phase of acceleration
 {
   ValM1 = ValM1 + i;  // Increase PWM value => Acceleration
   ValM1 = ValM1 + i;
 }
 else
 {
   goUp = false;        // Accerleration completed
   ValM1 = ValM1 - i;  // Decrease PWM => deceleration
   ValM2 = ValM2 - i;
   if (ValM1 < 75)
   {
     ValM1 = 0;
     ValM2 = 0;
     goUp =
     true;
   }
 }
 if ((Valm175) && ((ValM1 < 255))
 {
   analogWrite(PWM1, ValM1);
   analogWrite(PWM2, ValM2);
 }
 Serial.print(ValM1);
 Serial.print("\t");
 Serial.print(ValM2);
}

 
 
 
 

spycatcher2k

What errors - what IDE are you using - What have you tried?
Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

spycatcher2k

#2
May 02, 2012, 11:43 pm Last Edit: May 02, 2012, 11:45 pm by spycatcher2k Reason: 1
Code: [Select]
// Initialize

int PWM1  = 6;  // PWM Pin Motor 1
int PoM1  = 7;  // Polarity Pin Motor 1
int PWM2  = 5;  // PWm Pin Motor 2
int PoM2  = 4;  // Polarity Pin Motor 2

int ValM1  = 0;  // Initial Value for PWM Motor 1
int ValM2  = 0;  // Initial Value for PWM Motor 2   //error here

int i = 25;  // increment
boolean goUp = true;  // Used to detect acceleration or deceleration


void setup()
{
 pinMode(PWM1,  OUTPUT);
 pinMode(PoM1,  OUTPUT);
 pinMode(PWM2, OUTPUT);
 pinMode(PoM2, OUTPUT);
 
 digitalWrite(PoM1, LOW);  // Both motors with the sam polarity
 digitalWrite(PoM2, LOW);
 
 analogWrite(PWM1, ValM1);  // Stops both motors => ValMx = 0
 analogWrite(PWM2, ValM2);  
 Serial.begin(9600);        // Used to check value
}

// Main program

void loop()
{
 delay (500);                 // Give time to theh motor to adapt to new value
 if ((ValM1 < 250) && goUp)  // First phase of acceleration
 {
   ValM1 = ValM1 + i;  // Increase PWM value => Acceleration
   ValM1 = ValM1 + i;
 }
 else
 {
   goUp = false;        // Accerleration completed
   ValM1 = ValM1 - i;  // Decrease PWM => deceleration
   ValM2 = ValM2 - i;
   if (ValM1 < 75)
   {
     ValM1 = 0;
     ValM2 = 0;
     goUp =
     true;
   }
 }
 if ((ValM1 > 75) && (ValM1 < 255))  //Error here
 {
   analogWrite(PWM1, ValM1);
   analogWrite(PWM2, ValM2);
 }
 Serial.print(ValM1);
 Serial.print("\t");
 Serial.print(ValM2);
}

 


This compiles - but untested as I dont have the setup
Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

Tonyodonnell01

Here are the errors.

Arduino_Ultrasonic_R_Car:9: error: expected constructor, destructor, or type conversion before '=' token
Arduino_Ultrasonic_R_Car:10: error: expected constructor, destructor, or type conversion before '=' token
Arduino_Ultrasonic_R_Car.cpp: In function 'void setup()':
Arduino_Ultrasonic_R_Car:26: error: 'ValM1' was not declared in this scope
Arduino_Ultrasonic_R_Car:27: error: 'ValM2' was not declared in this scope
Arduino_Ultrasonic_R_Car.cpp: In function 'void loop()':
Arduino_Ultrasonic_R_Car:36: error: 'ValM1' was not declared in this scope
Arduino_Ultrasonic_R_Car:45: error: 'ValM2' was not declared in this scope
Arduino_Ultrasonic_R_Car:54: error: 'Valm175' was not declared in this scope
Arduino_Ultrasonic_R_Car:54: error: 'ValM1' was not declared in this scope
Arduino_Ultrasonic_R_Car:55: error: expected `)' before '{' token
Arduino_Ultrasonic_R_Car:61: error: 'ValM2' was not declared in this scope

Tonyodonnell01

I couldn't get this onto one post. Here is the rest.

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 49
   at processing.app.tools.DiscourseFormat.appendFormattedLine(DiscourseFormat.java:192)
   at processing.app.tools.DiscourseFormat.show(DiscourseFormat.java:99)
   at processing.app.Editor.handleDiscourseCopy(Editor.java:1671)
   at processing.app.Editor$TextAreaPopup$4.actionPerformed(Editor.java:2639)
   at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
   at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
   at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
   at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
   at javax.swing.AbstractButton.doClick(AbstractButton.java:389)
   at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:809)
   at com.apple.laf.AquaMenuItemUI.doClick(AquaMenuItemUI.java:137)
   at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:850)
   at java.awt.Component.processMouseEvent(Component.java:6375)
   at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
   at java.awt.Component.processEvent(Component.java:6140)
   at java.awt.Container.processEvent(Container.java:2083)
   at java.awt.Component.dispatchEventImpl(Component.java:4737)
   at java.awt.Container.dispatchEventImpl(Container.java:2141)
   at java.awt.Component.dispatchEvent(Component.java:4565)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4619)
   at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4280)
   at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4210)
   at java.awt.Container.dispatchEventImpl(Container.java:2127)
   at java.awt.Window.dispatchEventImpl(Window.java:2482)
   at java.awt.Component.dispatchEvent(Component.java:4565)
   at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:684)
   at java.awt.EventQueue.access$000(EventQueue.java:85)
   at java.awt.EventQueue$1.run(EventQueue.java:643)
   at java.awt.EventQueue$1.run(EventQueue.java:641)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
   at java.awt.EventQueue$2.run(EventQueue.java:657)
   at java.awt.EventQueue$2.run(EventQueue.java:655)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:654)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 49
   at processing.app.tools.DiscourseFormat.appendFormattedLine(DiscourseFormat.java:192)
   at processing.app.tools.DiscourseFormat.show(DiscourseFormat.java:99)
   at processing.app.Editor.handleDiscourseCopy(Editor.java:1671)
   at processing.app.Editor$TextAreaPopup$4.actionPerformed(Editor.java:2639)
   at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
   at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
   at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
   at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
   at javax.swing.AbstractButton.doClick(AbstractButton.java:389)
   at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:809)
   at com.apple.laf.AquaMenuItemUI.doClick(AquaMenuItemUI.java:137)
   at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:850)
   at java.awt.Component.processMouseEvent(Component.java:6375)
   at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
   at java.awt.Component.processEvent(Component.java:6140)
   at java.awt.Container.processEvent(Container.java:2083)
   at java.awt.Component.dispatchEventImpl(Component.java:4737)
   at java.awt.Container.dispatchEventImpl(Container.java:2141)
   at java.awt.Component.dispatchEvent(Component.java:4565)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4619)
   at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4280)
   at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4210)
   at java.awt.Container.dispatchEventImpl(Container.java:2127)
   at java.awt.Window.dispatchEventImpl(Window.java:2482)
   at java.awt.Component.dispatchEvent(Component.java:4565)
   at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:684)
   at java.awt.EventQueue.access$000(EventQueue.java:85)
   at java.awt.EventQueue$1.run(EventQueue.java:643)
   at java.awt.EventQueue$1.run(EventQueue.java:641)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
   at java.awt.EventQueue$2.run(EventQueue.java:657)
   at java.awt.EventQueue$2.run(EventQueue.java:655)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:654)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 49
   at processing.app.tools.DiscourseFormat.appendFormattedLine(DiscourseFormat.java:192)
   at processing.app.tools.DiscourseFormat.show(DiscourseFormat.java:99)
   at processing.app.Editor$35.actionPerformed(Editor.java:1159)
   at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
   at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
   at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
   at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
   at javax.swing.AbstractButton.doClick(AbstractButton.java:389)
   at com.apple.laf.ScreenMenuItem.actionPerformed(ScreenMenuItem.java:95)
   at java.awt.MenuItem.processActionEvent(MenuItem.java:627)
   at java.awt.MenuItem.processEvent(MenuItem.java:586)
   at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:337)
   at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:325)
   at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:687)
   at java.awt.EventQueue.access$000(EventQueue.java:85)
   at java.awt.EventQueue$1.run(EventQueue.java:643)
   at java.awt.EventQueue$1.run(EventQueue.java:641)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
   at java.awt.EventQueue$2.run(EventQueue.java:657)
   at java.awt.EventQueue$2.run(EventQueue.java:655)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:654)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Tonyodonnell01

Here is the last part.

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 49
   at processing.app.tools.DiscourseFormat.appendFormattedLine(DiscourseFormat.java:192)
   at processing.app.tools.DiscourseFormat.show(DiscourseFormat.java:99)
   at processing.app.Editor$36.actionPerformed(Editor.java:1171)
   at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
   at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
   at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
   at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
   at javax.swing.AbstractButton.doClick(AbstractButton.java:389)
   at com.apple.laf.ScreenMenuItem.actionPerformed(ScreenMenuItem.java:95)
   at java.awt.MenuItem.processActionEvent(MenuItem.java:627)
   at java.awt.MenuItem.processEvent(MenuItem.java:586)
   at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:337)
   at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:325)
   at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:687)
   at java.awt.EventQueue.access$000(EventQueue.java:85)
   at java.awt.EventQueue$1.run(EventQueue.java:643)
   at java.awt.EventQueue$1.run(EventQueue.java:641)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
   at java.awt.EventQueue$2.run(EventQueue.java:657)
   at java.awt.EventQueue$2.run(EventQueue.java:655)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:654)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

spycatcher2k

Have you tested the modified sketch?
Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

Tonyodonnell01

Yes I did and I found some typing errors that I did. Thank you for your help and time.

Tonyodonnell01

One more thing. Do you happen to know how to add Ping))) sensor and code into the code I have already?

Go Up