I need some help

i’m having problems with “verkefni_14”, i’m trying to get the program to start if i type “kasta” into the monitor, i had started on it but ran into some difficulties and i’m not one the same computer so i don’t have what i started on,
if someone can help me that would be great!.

verkefni_14.ino (1.33 KB)

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

Whenever possible post your code directly in the forum message using code tags (</> button on the toolbar), instead of as an attachment. If the code is longer than the forum will allow then an attachment is fine.

AsgeirDarri:
but ran into some difficulties

It’s much more helpful if you explain exactly what the difficulties are.

You never defined kasta. In your code kasta is a variable name. If you want that variable to contain the text “kasta” then you have to define it as such:

String kasta = "kasta";

Thanks for the input.
The "difficulties" i was having was the fact that i couldn't find a way to write "kasta" into the monitor and have that as a variable to an IF command which would set of the dice which i have already made.

//i'm using this to read the monitor
if (Serial.available() > 1)
{
x=Serial.read();

and i tried to to some thing like

if (x = kasta){
}
though that's all that i could thing of, hopefully this helps

Serial.read() returns one byte. So you need to read 5 bytes to get "kasta". This thread is all about how to read from the serial port and parse the input to take actions based on serial input.

You forgot the code tags I requested you to use in my previous post.

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. Using code tags and other important information is explained in the How to use this forum post. Please read it.

You forgot to Auto Format as I requested in my previous post.

AsgeirDarri:
The “difficulties” i was having was the fact that i couldn’t find a way to write “kasta” into the monitor and have that as a variable to an IF command which would set of the dice which i have already made.

Did you try making the change I recommended in my previous post? If so then what was the result?

AsgeirDarri:
if (x = kasta){

NOOOOO!!! you need to use ==, not =, as you already had in your sketch.

//i'm looking for a way to make it so that when i type the word "Kasta", i can use that as an if condition to activate the dice
int led1 = 1;
int led2 = 2;
int led3 = 3;
int led4 = 4;
int led5 = 5;
int led6 = 6;
int led7 = 7;
int randNumber;
int x;
void setup()
{
  Serial.begin(9600);
}
void loop()
{
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT);
  randomSeed(analogRead(0));
  randNumber = random(1, 6);
  Serial.println(randNumber);
  delay(50);
  //i'm using this to read from the monitor
  if (Serial.available() > 1)
    x = Serial.parseInt();

  if (randNumber == 1) {
    digitalWrite(led7, HIGH);
    digitalWrite(led1, LOW);
  }
  if (randNumber == 2) {
    digitalWrite(led1, HIGH);
    digitalWrite(led6, HIGH);
  }
  if (randNumber == 3) {
    digitalWrite(led1, HIGH);
    digitalWrite(led6, HIGH);
    digitalWrite(led7, HIGH);
  }
  if (randNumber == 4) {
    digitalWrite(led1, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);
    digitalWrite(led6, HIGH);
  }
  if (randNumber == 5) {
    digitalWrite(led1, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);
    digitalWrite(led6, HIGH);
    digitalWrite(led7, HIGH);
  }
  if (randNumber == 6) {
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);
    digitalWrite(led5, HIGH);
    digitalWrite(led6, HIGH);

  }
}

Look for the Serial Input Basics thread by @Robin2. That will explain all you need to know. Google "Arduino Serial Input Basics"

Don't double post - it just wastes everyone's time.

...R
Serial Input Basics

Threads merged.