Pages: [1]   Go Down
Author Topic: Need help getting rid of code errors  (Read 733 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

// 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);
}

  
  
 
  
« Last Edit: May 02, 2012, 04:47:57 pm by Tonyodonnell01 » Logged

Scotland
Offline Offline
Edison Member
*
Karma: 24
Posts: 1215
Have you had your Arduino fix today?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What errors - what IDE are you using - What have you tried?
Logged

Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

Scotland
Offline Offline
Edison Member
*
Karma: 24
Posts: 1215
Have you had your Arduino fix today?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
// 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
« Last Edit: May 02, 2012, 04:45:58 pm by spycatcher2k » Logged

Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Logged

Scotland
Offline Offline
Edison Member
*
Karma: 24
Posts: 1215
Have you had your Arduino fix today?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you tested the modified sketch?
Logged

Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: