Laser transmitter transmitts the whole alphabet instead of a single character

Hello Community!

As the title suggests, I am currently working on some kind of multi-emitting laser communication system.
But now my little communicator has that weird bug, that it transmits my whole defined alphabet, which is not exactly what I planed.
Since this is my first project and my programming skills are barely existent as of now, I am quite baffled about that and have no clue how to fix it.
If anybody has the time to point my mistake out, or to atleast give me a hint why my programm acts the way it does, I would be very thankful!

Here's the code:

#include <Keyboard.h>

char incomingmessage[] =""; // for incoming serial data
char message="";

#include <Keyboard.h>



char incomingmessage[] =""; // for incoming serial data
char message="";




void setup() {
  // put your setup code here, to run once:

pinMode (2, OUTPUT);
pinMode (3, OUTPUT);
pinMode (4, OUTPUT);
pinMode (5, OUTPUT);
pinMode (6, OUTPUT);
  Serial.begin(9600);
    Serial.print("start\r\n");
 
 
    Serial.println("Type something!");

}







void loop() {
  // put your main code here, to run repeatedly:
char input;
 


    if(Serial.available()){
        message = Serial.read();
        Serial.print("message") ;
        

if (message=="a")
  {
    digitalWrite (2, HIGH);
    digitalWrite (3, LOW);
    digitalWrite (4, LOW);
    digitalWrite (5, LOW);
    digitalWrite (6, LOW);
    delay (35);
    }

 if (message="b")
  {
    digitalWrite (2, LOW);
    digitalWrite (3, HIGH);
    digitalWrite (4, LOW);
    digitalWrite (5, LOW);
    digitalWrite (6, LOW);
    delay (35);
  }

  if (message="c")
  {
    digitalWrite (2, LOW);
    digitalWrite (3, LOW);
    digitalWrite (4, HIGH);
    digitalWrite (5, LOW);
    digitalWrite (6, LOW);
    delay (35);  
    }

  if (message="d")
    {
      digitalWrite (2, LOW);
      digitalWrite (3, LOW);
      digitalWrite (4, LOW);
      digitalWrite (5, HIGH);
      digitalWrite (6, LOW);
      delay (35);  
    }

   if (message="e")
    {
      digitalWrite (2, HIGH);
      digitalWrite (3, HIGH);
      digitalWrite (4, LOW);
      digitalWrite (5, LOW);
      digitalWrite (6, LOW);
      delay (35);
    }
   if (message="f")
     {
      digitalWrite (2, LOW);
      digitalWrite (3, HIGH);
      digitalWrite (4, HIGH);
      digitalWrite (5, LOW);
      digitalWrite (6, LOW);
      delay (35);
     }
  if (message="g")
  {
    digitalWrite (2, LOW);
    digitalWrite (3, LOW);
    digitalWrite (4, HIGH);
    digitalWrite (5, HIGH);
    digitalWrite (6, LOW);
    delay (35);
  }
   if (message="h")
   {
    digitalWrite (2, LOW);
    digitalWrite (3, LOW);
    digitalWrite (4, LOW);
    digitalWrite (5, HIGH);
    digitalWrite (6, HIGH);
    delay (35);
   }
  if (message="i") 
  {
    digitalWrite (2, HIGH);
    digitalWrite (3, LOW);
    digitalWrite (4, HIGH);
    digitalWrite (5, LOW);
    digitalWrite (6, LOW);
    delay(35);
  }
  if (message="j")
  {
  digitalWrite (2, LOW);
  digitalWrite (3, HIGH);
  digitalWrite (4, LOW);
  digitalWrite (5, HIGH);
  digitalWrite (6, LOW);
  delay (35);
  }
  if (message="k")
  {
  digitalWrite (2, LOW);
  digitalWrite (3, LOW);
  digitalWrite (4, HIGH);
  digitalWrite (5, LOW); 
  delay (35);
  }
  if (message="l")
  {
  digitalWrite (2, HIGH);
  digitalWrite (3, LOW);
  digitalWrite (4, LOW);
  digitalWrite (5, LOW);
  digitalWrite (6, HIGH);
  delay (35);
  }

  if (message="m")
  {
    digitalWrite (2, HIGH);
    digitalWrite (3, HIGH);
    digitalWrite (4, HIGH);
    digitalWrite (5, LOW);
    digitalWrite (6, LOW);
    delay (35);
  }
 if (message="n")
 {
  digitalWrite (2, LOW);
  digitalWrite (3, HIGH);
  digitalWrite (4, HIGH);
  digitalWrite (5, HIGH);
  digitalWrite (6, LOW);
  delay (35) ;
 }
 if (message="o")
 {
  digitalWrite (2, LOW);
  digitalWrite (3, LOW);
  digitalWrite (4, HIGH);
  digitalWrite (5, HIGH);
  digitalWrite (6, HIGH);
  delay (35);
 }
if (message="p")
{
  digitalWrite (2, HIGH);
  digitalWrite (3, LOW);
  digitalWrite (4, HIGH);
  digitalWrite (5, LOW);
  digitalWrite (6, HIGH);
  delay (35);
}
if (message="q")
{
  digitalWrite (2, HIGH);
  digitalWrite (3, HIGH);
  digitalWrite (4, LOW);
  digitalWrite (5, HIGH);
  digitalWrite (6, LOW);
  delay (35);
}
if (message="r")
{
  digitalWrite (2, HIGH);
  digitalWrite (3, HIGH);
  digitalWrite (4, LOW);
  digitalWrite (5, LOW);
  digitalWrite (6, HIGH);
  delay (35);
}
if (message="s")
{
  digitalWrite (2, LOW);
  digitalWrite (3, HIGH);
  digitalWrite (4, HIGH);
  digitalWrite (5, LOW);
  digitalWrite (6, HIGH);
  delay (35);
}
if (message="t")
{
  digitalWrite (2, HIGH);
  digitalWrite (3, LOW);
  digitalWrite (4, LOW);
  digitalWrite (5, HIGH);
  digitalWrite (6, HIGH);
  delay(35);
  }

if (message="u")
{
  digitalWrite (2, LOW);
  digitalWrite (3, HIGH);
  digitalWrite (4, LOW);
  digitalWrite (5, HIGH);
  digitalWrite (6, HIGH);
  delay(35);
}
if (message="v")
{
  digitalWrite (2, HIGH);
  digitalWrite (3, HIGH);
  digitalWrite (4, HIGH);
  digitalWrite (5, HIGH);
  digitalWrite (6, LOW);
  delay(35);
}
if (message="w")
{
  digitalWrite (2, LOW);
  digitalWrite (3, HIGH);
  digitalWrite (4, HIGH);
  digitalWrite (5, HIGH);
  digitalWrite (6, HIGH);
  delay (35);
}
if (message="x")
{
  digitalWrite (2, HIGH);
  digitalWrite (3, LOW);
  digitalWrite (4, HIGH);
  digitalWrite (5, HIGH);
  digitalWrite (6, HIGH);
  delay (35);
}
if (message="y")
{
  digitalWrite (2, HIGH);
  digitalWrite (3, HIGH);
  digitalWrite (4, LOW);
  digitalWrite (5, HIGH);
  digitalWrite (6, HIGH);
  delay (35);
  }
 if (message="z")
 {
  digitalWrite (2, HIGH);
  digitalWrite (3, HIGH);
  digitalWrite (4, HIGH);
  digitalWrite (5, LOW);
  digitalWrite (6, HIGH);
  delay(35);
 }
 if (message=" ")
 {
 digitalWrite (1, HIGH);
 digitalWrite (2, HIGH);
 digitalWrite (3, HIGH);
 digitalWrite (4, HIGH);
 digitalWrite (5, HIGH);
 digitalWrite (5, HIGH);
 delay (35);
 }

  digitalWrite (1, LOW);
  digitalWrite (2, LOW);
  digitalWrite (3, LOW);
  digitalWrite (4, LOW);
  digitalWrite (5, LOW);
  digitalWrite (6, LOW);
  delay (500);

 




        memset (message, 0, sizeof (message));
        Serial.println(message);
    }
}

edit, code tags

Code tags, please!

I am not sure what that means.

After reading the post "How to get the best out of the forum" (at the head of every forum topic), please edit your post to add code tags.

You cannot compare character arrays (C-strings) like this.

if(message=="a")

Use the strcmp() function instead, or just compare individual characters, e.g. 'a' in single quotes.

Take some basic tutorials in C. Learn that = is not the same as ==

So if I understand this correct,
either I change "a" to 'a', or I use strcmp() function?

Yes use the strcmp function to compare strings. If you want to use single characters you still have to use the equality operator == not the assignment operator =

It worked.
It was a stupid beginners mistake, good that there are patient people with knowledge like you jremington, thank you!

Yeah I corrected those missing =
thanks for pointing that out.

As of now, I still dont perfectly understand the difference between arrays and strings in thas manner and am far away from understanding why and how to compare them.

But according to my understanding I have to breal the array (or string) up into single characters for my transmission process right?

Anyways, right now it does what it is supposed to, it accepts long messages, breaks them down into the single characters and transmitts them one at a step.
Thanks for your time and help.

A string is in its essence just an array of characters. C style strings have a null character, denoted as '\0' marking the end of the string. So a string is an array, but an array is not a string.

If you're implementing the actual transmission mechanism yourself, then most probably yes. You can iterate the string characters until you reach the null character.

    char myString[] = "Hello there!";
    char c;
    unsigned int n = 0;

    while ((c = myString[n++]) != '\0') {
        // TODO transmit the character in the c variable
    }

There are lots of tutorials on line. You might start with this one: C - Strings

thank you for taking the time to explain.

so if a string is basically an array+1 whats the point of them anyway?

Yeah I have to implement the transmission mechanism myself, because I want to transmit data in quite a unusual way, but since you read the code, you should see where I am trying to go.
I want to send letters (later on digits and signs) with one change of state, instead of several zeros and ones.
I saw a video a while ago about some dudes from an american univesity, they've built a laser transmission system and complained, that they can't get past a specific transmission rate, since the sensor's adaption speed is too low and the got messy results at high pulsing frequencies.
So I thought, more lasers, equals more possible states than zero and one, equals the possibility to send letters and so on with one change of state, equals higher transmission rate.
So here I am, learning all that stuff, I would never thought I'd learn.
And here you are, "having to "explain me pretty basic stuff, for which I am very thankful!

Thanks, gonna look right into it

C-strings originally formed the basis for all text manipulation in C/C++, with standard functions to handle required actions.

Fascinating, so since now there is the possibility of arrays, one could argue that they are now more or less like an old tradition that survived, or am I wrong?
Like I mentioned, I am just about to get into all that stuff. It's less then two weeks since I started, so my knowledge still is very limited.
Apart from some youtube videos, this is the first input from knowledgeable people like you, and I have to say thanks once again.

I forgot to mention that C-strings also handle human readable data input and output, so they are the primary basis for human-computer interaction.

You still read text and numbers on a screen and type in names and numbers on a traditional or touch screen keyboard, so no, it is not an "old tradition that survived". In fact text is an essential means of data transmission that is extremely difficult to replace.

As you know, since you want to transmit a human readable message.

true, but a char array is text too, or am I wrong?
or is it, because once digits come in place I cant use a char array?

The zero terminator of a C-string is REQUIRED for the string functions to work properly. Leaving it out can lead to program malfunction and computer crashes.

It is, if you decide it is. But it's not a string in the C language. For it to be a string it HAS to be terminated with the null character. As jremington states, it's required for the string functions in the standard library to function properly.

What a string is in the C language is really just convention/tradition, other languages implements string functionality in different ways. You can even develop your own string implementation in C if you really want to.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.