Skip to main content
Improved formatting
Source Link
BrettFolkins
  • 4.4k
  • 1
  • 15
  • 26

/This is a small example of a bigger code, Basically i want to convert a string into a int value. in my real code, I receive a string "Slider 255" the number after slider changes from 0 to 255, so I want a int value to be = to that number/

#include <Servo.h> Servo myServo;

I want to convert a string into a int val = 0; String s = ""; void setup() {

Serial.begin(9600); myServo.attach(9); }

void loop() {

while(BT.available() >0){ s = Serialvalue.read(); // which wiil be in my real code, I receive a string "Slider 255" the number betweenafter slider changes from 0 andto 255 // So, so I want vala int value to be =equal to ehatever the string is. So far I have try this but it doesn´t workthat number. // first attempt # 1 val = s This is a small example of the code: myServo.write(val);

// Second attempt # 2 Serial.println(s) val = Serial.read(); myServo.write(val);

}}

#include <Servo.h>
Servo myServo;


int val = 0;
String s = "";
void setup() {

  Serial.begin(9600);
  myServo.attach(9);
}

void loop() {
  while(BT.available() >0){
  s =  Serial.read(); // which wiil be a number between 0 and 255
  // So I want val to be = to ehatever the string is. So far I have try this but it doesn´t work.
  // first attempt # 1
  val = s:
  myServo.write(val); 

  // Second attempt # 2 
  Serial.println(s)
  val = Serial.read();
   myServo.write(val);
  }
}

/This is a small example of a bigger code, Basically i want to convert a string into a int value. in my real code, I receive a string "Slider 255" the number after slider changes from 0 to 255, so I want a int value to be = to that number/

#include <Servo.h> Servo myServo;

int val = 0; String s = ""; void setup() {

Serial.begin(9600); myServo.attach(9); }

void loop() {

while(BT.available() >0){ s = Serial.read(); // which wiil be a number between 0 and 255 // So I want val to be = to ehatever the string is. So far I have try this but it doesn´t work. // first attempt # 1 val = s: myServo.write(val);

// Second attempt # 2 Serial.println(s) val = Serial.read(); myServo.write(val);

}}

I want to convert a string into a int value. in my real code, I receive a string "Slider 255" the number after slider changes from 0 to 255, so I want a int value to be equal to that number. This is a small example of the code:

#include <Servo.h>
Servo myServo;


int val = 0;
String s = "";
void setup() {

  Serial.begin(9600);
  myServo.attach(9);
}

void loop() {
  while(BT.available() >0){
  s =  Serial.read(); // which wiil be a number between 0 and 255
  // So I want val to be = to ehatever the string is. So far I have try this but it doesn´t work.
  // first attempt # 1
  val = s:
  myServo.write(val); 

  // Second attempt # 2 
  Serial.println(s)
  val = Serial.read();
   myServo.write(val);
  }
}
Source Link

How to convert a String number Into a int value?

/This is a small example of a bigger code, Basically i want to convert a string into a int value. in my real code, I receive a string "Slider 255" the number after slider changes from 0 to 255, so I want a int value to be = to that number/

#include <Servo.h> Servo myServo;

int val = 0; String s = ""; void setup() {

Serial.begin(9600); myServo.attach(9); }

void loop() {

while(BT.available() >0){ s = Serial.read(); // which wiil be a number between 0 and 255 // So I want val to be = to ehatever the string is. So far I have try this but it doesn´t work. // first attempt # 1 val = s: myServo.write(val);

// Second attempt # 2 Serial.println(s) val = Serial.read(); myServo.write(val);

}}