Home c++ Skatech size decrease Arduino

Skatech size decrease Arduino

Author

Date

Category

Trying to stuff this sketch in Atmega8.

You need to reduce the size of the sketch at 1022 bytes (minimum), but I do not know how

# include & lt; arduino.h & gt;
#Include "servosmooth.h" // https://github.com/alexGyver/gyverlibs/tree/master/Servosmooth
#Define Engine_pin 11.
#Define Servo_Pin 9.
#Define Reverse_Pin 5.
Long Last_m_time = 0;
int ENGINE_PWM = 0;
int is_reverse_engine = 0;
int servo_angle = 90;
SERVOSMOOTH STEERING;
void setup ()
{
 Serial.begin (9600);
 Serial.settimeout (20);
 Pinmode (Engine_Pin, Output);
 Pinmode (SERVO_PIN, OUTPUT);
 Pinmode (Reverse_Pin, Output);
 Steering.attach (SERVO_PIN);
 Steering.Setspeed (130);
 Steering.Setaccel (0.1);
}
String GetValue (String Data, Char Separator, Int Index)
{
 INT FOUND = 0;
 INT STRINDEX [] = {0, -1};
 int maxindex = data.length () - 1;
 For (int i = 0; i & lt; = maxindex & amp; & amp; found & lt; = index; i ++)
 {
  if (data.charat (i) == separator || i == maxindex)
  {
   Found ++;
   STRINDEX [0] = strindex [1] + 1;
   Strindex [1] = (i == Maxindex)? I + 1: I;
  }
 }
 RETURN FOUND & GT; index? Data.Substring (Strindex [0], Strindex [1]): "";
}
Void Decode_Message (String Data)
{
 // Rowes 90: 120: 0
 SERVO_ANGLE = GETVALUE (DATA, ':', 0) .TOINT ();
 Engine_pwm = getValue (Data, ':', 1) .TOINT ();
 is_reverse_engine = getValue (Data, ':', 2) .TOINT ();
}
Void Reset_vehicle ()
{
 ENGINE_PWM = 0;
 is_reverse_engine = 0;
 SERVO_ANGE = 90;
}
Void Check_Connection ()
{
 If ((Millis () - Last_m_Time) & gt; 700)
 {
  RESET_VEHICLE ();
 }
}
void loop ()
{
 String Data = Serial.ReadStringuntil ('\ n');
 if (data.length () & gt; 0)
 {
  Last_m_time = Millis ();
  Decode_Message (DATA);
 }
 steering.settargetdeg (SERVO_ANGE);
 AnalogWrite (Engine_pin, Engine_PWM);
 DigitalWrite (Reverse_Pin, is_reverse_engine);
 check_connection ();
 steering.tick ();
}

UPD:

What I could do (now need to reduce another 824 byte):

# include & lt; arduino.h & gt;
#Include "servosmooth.h" // https://github.com/alexGyver/gyverlibs/tree/master/Servosmooth
#Define Engine_pin 11.
#Define Servo_Pin 9.
#Define Reverse_Pin 5.
uint32_t last_m_time = 0;
BYTE ENGINE_PWM = 0;
byte is_reverse_engine = 0;
BYTE SERVO_ANGLE = 90;
SERVOSMOOTH STEERING;
void setup ()
{
 Serial.begin (9600);
 Serial.settimeout (20);
 Pinmode (Engine_Pin, Output);
 Pinmode (SERVO_PIN, OUTPUT);
 Pinmode (Reverse_Pin, Output);
 Steering.attach (SERVO_PIN);
 Steering.Setspeed (130);
 Steering.Setaccel (0.1);
}
String GetValue (String & Amp; Data, Char Separator, UINT8_T INDEX)
{
 INT FOUND = 0;
 INT STRINDEX [] = {0, -1};
 uint8_t maxindex = data.length () - 1;
 For (uint8_t i = 0; i & lt; = maxindex & amp; & amp; found & lt; = index; i ++)
 {
  if (data.charat (i) == separator || i == maxindex)
  {
   Found ++;
   STRINDEX [0] = strindex [1] + 1;
   Strindex [1] = (i == Maxindex)? I + 1: I;
  }
 }
 RETURN FOUND & GT; index? Data.Substring (Strindex [0], Strindex [1]): "";
}
Void Decode_Message (String & Amp; DATA)
{
 SERVO_ANGLE = GETVALUE (DATA, ':', 0) .TOINT ();
 Engine_pwm = getValue (Data, ':', 1) .TOINT ();
 is_reverse_engine = getValue (Data, ':', 2) .TOINT ();
}
Void Reset_vehicle ()
{
 ENGINE_PWM = 0;
 is_reverse_engine = 0;
 SERVO_ANGE = 90;
}
Void Check_Connection ()
{
 If ((Millis () - Last_m_Time) & gt; 700)
 {
  RESET_VEHICLE ();
 }
}
void loop ()
{
 String Data = Serial.ReadStringuntil ('\ n');
 if (data.length () & gt; 0)
 {
  Last_m_time = Millis ();
  Decode_Message (DATA);
 }
 steering.settargetdeg (SERVO_ANGE);
 AnalogWrite (Engine_pin, Engine_PWM);
 DigitalWrite (Reverse_Pin, is_reverse_engine);
 check_connection ();
 steering.tick ();
}

Answer 1

Hyver library in principle does not fit atmega8.

In order to make sure to try to compile the sketch that does not do anything, simply connects libraries:

# include & lt; arduino.h & gt;
#Include "servosmooth.h" // https://github.com/alexGyver/gyverlibs/tree/master/Servosmooth
#Define Engine_pin 11.
#Define Servo_Pin 9.
#Define Reverse_Pin 5.
SERVOSMOOTH STEERING;
void setup ()
{
  Serial.begin (9600);
  Serial.settimeout (20);
  Pinmode (Engine_Pin, Output);
  Pinmode (SERVO_PIN, OUTPUT);
  Pinmode (Reverse_Pin, Output);
  Steering.attach (SERVO_PIN);
  Steering.Setspeed (130);
  Steering.Setaccel (0.1);
}
void loop ()
{
}

Possible options:

  1. Choose more “bold” chip.
  2. Do not use libraries, but to implement the desired logic yourself.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions