code in code

hello

is there a way that i can write arduino ide code in the serial monitor and that my arduino execute it?
example: i write in the serial monitor int lol = 13; that in the arduino this realy will execute?
and if i write in the serial monitor:

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

that it will be execute and the led will blink?

thanks

Not with the standard IDE but you may be interested in http://bitlash.net/

i dont understand bitlash

is there another thing i can use.

and it must execute thing from serial terminal.
but when the code is running i have 10 buttons connected to arduino to write code too.
and that code must be executed too.
so it must works too with for example: buttons as keys.
i have when i pres 1x and the first button there comes the letter a.
but when i press 2x on the first button there comes the letter k.
and that makes the code to execute.

how to do that??

thanks

how to do that??

Frankly, I don't think you can.

so it must works too with for example: buttons as keys.

Buttons are for holding shirts closed. Keys are for opening locks. I don't think that they are interchangeable.

i have when i pres 1x and the first button there comes the letter a.

When you press what one times? What first button? Where does the letter a come from? Where does it go to?

arduino123456789:
is there a way that i can write arduino ide code in the serial monitor and that my arduino execute it?
example: i write in the serial monitor int lol = 13; that in the arduino this realy will execute?
and if i write in the serial monitor:

/*

Blink


that it will be execute and the led will blink?

thanks

this may be what you want...

attache a LED to pin 11 and a button to pin2

enter either a 0 or 1 in the serial monitor to see the LED do one of two different routines.

#include <math.h>
int ledPin = 11;
int buttonPin = 2;
int lastPressed;
int state = 0;
unsigned long startTime;

void setup() 
{                
  // initialize the digital pin as an output.
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);  
}

void loop()
{
  if (Serial.available())
  {
    char myChar = Serial.read();
    if (myChar == '0') state = 0;
    else if (myChar == '1') state = 1;
  }
  int pressed = digitalRead(buttonPin); 
  if (pressed)
  {
    if (pressed != lastPressed)
    {
      state++;
      if (state > 1) state = 0;// add more light tricks by adding states
    }
  }
  lastPressed = pressed;
  if (state == 0)
  {
    prettyFade();
  }
  else if (state == 1)
  {
    blinkyLed();
  }
  else if (state == 2)
  {
    //another cool led trick?
  }
}

void prettyFade()
{
  float val = (exp(sin(millis()/2000.0*PI)) - 0.36787944)*108.0;
  analogWrite(ledPin, val);
}

void blinkyLed()
{
  if (millis() - startTime >= 100UL)
  {
    digitalWrite(ledPin, !digitalRead(ledPin));
    startTime += 100UL;
  }
}

Arduino code is compiled and then downloading into the on-chip flash memory by
the bootloader, it can only run from flash, and only the bootloader can alter flash,
so there is no way to alter the code at runtime.

If you ran an interpreted language in the Arduino it would be different, as the flash
would contain the interpreter and the interpreter would execute commands from
whatever source it wanted.

BulldogLowell:

arduino123456789:
is there a way that i can write arduino ide code in the serial monitor and that my arduino execute it?
example: i write in the serial monitor int lol = 13; that in the arduino this realy will execute?
and if i write in the serial monitor:

/*

Blink


that it will be execute and the led will blink?

thanks

this may be what you want...

attache a LED to pin 11 and a button to pin2

enter either a 0 or 1 in the serial monitor to see the LED do one of two different routines.

#include <math.h>

int ledPin = 11;
int buttonPin = 2;
int lastPressed;
int state = 0;
unsigned long startTime;

void setup()
{               
  // initialize the digital pin as an output.
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT); 
}

void loop()
{
  if (Serial.available())
  {
    char myChar = Serial.read();
    if (myChar == '0') state = 0;
    else if (myChar == '1') state = 1;
  }
  int pressed = digitalRead(buttonPin);
  if (pressed)
  {
    if (pressed != lastPressed)
    {
      state++;
      if (state > 1) state = 0;// add more light tricks by adding states
    }
  }
  lastPressed = pressed;
  if (state == 0)
  {
    prettyFade();
  }
  else if (state == 1)
  {
    blinkyLed();
  }
  else if (state == 2)
  {
    //another cool led trick?
  }
}

void prettyFade()
{
  float val = (exp(sin(millis()/2000.0*PI)) - 0.36787944)*108.0;
  analogWrite(ledPin, val);
}

void blinkyLed()
{
  if (millis() - startTime >= 100UL)
  {
    digitalWrite(ledPin, !digitalRead(ledPin));
    startTime += 100UL;
  }
}

this can i use for another project that i am doing.
but this is not where i am looking for for this project.

thanks for all your replies.

this is not where i am looking for for this project.

Perhaps you could explain what the project is. Are you looking to enter arbitrary code in the Serial monitor and have it executed by the Arduino or are there only a limited number of programs that you want to run ?

You seem to have described a solution that you are looking for and found that it is impossible to implement, but if you describe what you are trying to do then there may be a different way to achieve it.

You could have several different functions (program segments) in your Arduino program and select which one you want to run using a keypad or with data from the Serial Monitor.

However this implies that the functions are written before the program is uploaded to the Arduino.

...R

i dont understand bitlash

So that is your problem. Try and udonderstand it, do not just give up. No one is going to do your protect for you.