Jump to content

 

#include <Servo.h>

#define ACTIVATED LOW

Servo NovaServo_1; //Head Movement - Front and Back
Servo NovaServo_2; //Head Rotation - Clockwise and Anticlockwise
Servo NovaServo_3; //Head Rotation - Up and Down
Servo NovaServo_4; //Whole Body Rotation - Z axis
Servo NovaServo_5; //Head Movement - Up and Down

int joystick1_x = A9;
int joystick1_y = A11;
int joystick2_x = A13;
int joystick2_y = A15;

int joystick1_sw = 43;
int joystick2_sw = 45;

int value1_x;
int value1_y;
int value2_x;
int value2_y;

int value1_sw;
int value2_sw;

int value1_xF = 90;
int value1_yF = 110;
int value2_xF = 90;
int value2_yF = 100;

int degree = 90;

float filter1_x = 0.05;
float filter1_y = 0.05;
float filter2_x = 0.08;
float filter2_y = 0.08;

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

  pinMode(joystick1_sw, INPUT_PULLUP);
  pinMode(joystick2_sw, INPUT_PULLUP);

  NovaServo_1.attach(32);
  NovaServo_2.attach(34);
  NovaServo_3.attach(36);
  NovaServo_4.attach(38);
  NovaServo_5.attach(40);

  NovaServo_1.write(110);
  NovaServo_2.write(90);
  NovaServo_3.write(100);
  NovaServo_4.write(90);
  NovaServo_5.write(95);
}

void loop() {
  
  value1_x = analogRead(joystick1_x);
  value1_y = analogRead(joystick1_y);
  value2_x = analogRead(joystick2_x);
  value2_y = analogRead(joystick2_y);
  
  value1_sw = digitalRead(joystick1_sw);
  value2_sw = digitalRead(joystick2_sw);

  value1_x = map(value1_x, 0, 1024, 170, 10);
  value1_y = map(value1_y, 0, 1024, 50, 170);
  value2_x = map(value2_x, 0, 1024, 40, 140);
  value2_y = map(value2_y, 0, 1024, 40, 160);

 value1_xF = value1_xF * (1 - filter1_x) + value1_x * filter1_x;
 value1_yF = value1_yF * (1 - filter1_y) + value1_y * filter1_y;
 value2_xF = value2_xF * (1 - filter2_x) + value2_x * filter2_x;
 value2_yF = value2_yF * (1 - filter2_y) + value2_y * filter2_y;

  if (value1_sw == ACTIVATED) {
    if(degree < 141) degree = degree + 2;
  }
  if (value2_sw == ACTIVATED) {
    if(degree > 89) degree = degree - 2;
} 
  delay(30);

  if(value1_yF > 80)  NovaServo_1.write(value1_yF);
                      NovaServo_2.write(value2_xF);
  if(value2_yF > 65)  NovaServo_3.write(value2_yF);
                      NovaServo_4.write(value1_xF);
                      NovaServo_5.write(degree);
}

Im trying to code a creoqode nova but i dont understand the errors i get in arduino one is error stray.\'342'

heres the code

 

MAIN PC

  • NVIDIA TITAN X (pascal)
  • INTEL CORE I7 8700K
  • ASUS STRIX Z370-E
  • PHANTEKS ENTHOO EVOLVE TG
  • WD BLACK 512GB PCIE SSD
  • WD 2TB BLACK DRIVE
  • CORSAIR 860 POWER SUPPLY
  • HYPERX FURY 16GB DDR4
  • RAZER BLACKWIDOW CHROMA V2
  • RAZER NAGA CHROMA 16000 DPI SENSOR
  • ASUS PB278Q
  • ASUS VS248
  • ASTRO A50 GEN 3

SECONDARY PC

  • AMD RYZEN 1600X
  • ASUS ROG STRIX 1060 OC
  • ASUS STRIX CROSSHAIR
  • KINGSTON 128GB SSD AND SAMSUNG 830 EVO 128GB RAID
  • SEAGATE BARRACUDA 2TB
  • PHANTEKS ECLIPSE P400 TG
  • LOGITECH HEADSET
  • RAZER BLACKWIDOW ULTIMATE
  • RAZER MAMABA TOURNEMANT
  • ACER AND ASUS 1080P MONITORS
  • cheap firehazard power supply
Link to comment
https://linustechtips.com/topic/961313-arduino-code/
Share on other sites

Link to post
Share on other sites

Just now, fpo said:

Which line is 342? 

 

Also just to be sure, you’re using the latest Arduino programming program right? 

i am using the latest program and this is the line it refers to

if (value2_sw == ACTIVATED) {

   ^

MAIN PC

  • NVIDIA TITAN X (pascal)
  • INTEL CORE I7 8700K
  • ASUS STRIX Z370-E
  • PHANTEKS ENTHOO EVOLVE TG
  • WD BLACK 512GB PCIE SSD
  • WD 2TB BLACK DRIVE
  • CORSAIR 860 POWER SUPPLY
  • HYPERX FURY 16GB DDR4
  • RAZER BLACKWIDOW CHROMA V2
  • RAZER NAGA CHROMA 16000 DPI SENSOR
  • ASUS PB278Q
  • ASUS VS248
  • ASTRO A50 GEN 3

SECONDARY PC

  • AMD RYZEN 1600X
  • ASUS ROG STRIX 1060 OC
  • ASUS STRIX CROSSHAIR
  • KINGSTON 128GB SSD AND SAMSUNG 830 EVO 128GB RAID
  • SEAGATE BARRACUDA 2TB
  • PHANTEKS ECLIPSE P400 TG
  • LOGITECH HEADSET
  • RAZER BLACKWIDOW ULTIMATE
  • RAZER MAMABA TOURNEMANT
  • ACER AND ASUS 1080P MONITORS
  • cheap firehazard power supply
Link to comment
https://linustechtips.com/topic/961313-arduino-code/#findComment-11654126
Share on other sites

Link to post
Share on other sites

8 minutes ago, Andy_Sendra said:

i am using the latest program and this is the line it refers to

if (value2_sw == ACTIVATED) {

   ^

I was going to say try making that “else if” 

however google says there may be “stray characters”

Spoiler

 

Another link confirms that it’s something there that “it’s invisible characters, usually when copied from a webpage” as in HTML a new line is /n or \n. (I forget which) 

 

https://forum.arduino.cc/index.php?topic=459733.0

 

try deleting all the new lines and indents and typing those back in yourself. 

Link to comment
https://linustechtips.com/topic/961313-arduino-code/#findComment-11654144
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×