fbpx

www.huvitera.ee/arduino-17A

				
					//NR1 - Morse.
//Kordab 1000x signaali

char stringToMorseCode[] = "";


int audio8 = 8;      // output audio on pin 8

int note = 1200;      // music note/pitch


int dotLen = 300;     // length of the morse code 'dot'

int dashLen = dotLen * 5;    // length of the morse code 'dash'


void setup() {

  Serial.begin(9600);

}

void loop() {
  for (;;) {
    String stringToMorseCode = "auto"; // Replace "HELLO" with your desired message

    for (int i = 0; i < stringToMorseCode.length(); i++) {
      char tmpChar = toLowerCase(stringToMorseCode[i]);
      GetChar(tmpChar);
    }
    delay(2000); // Delay between repetitions
  }
}


void MorseDot()
{

  tone(audio8, note, dotLen); // start playing a tone

  delay(dotLen);              // hold in this position

}


void MorseDash()

{

  tone(audio8, note, dashLen);  // start playing a tone

  delay(dashLen);               // hold in this position

}


void GetChar(char tmpChar)

{

  switch (tmpChar) {

    case 'a':

    MorseDot();

    delay(100);

    MorseDash();

    delay(500);

    break;

    case 'b':

    MorseDash();

    delay(100);

    MorseDot();

    delay(100);

    MorseDot();

    delay(100);

    MorseDot();

    delay(100);

    break;

    case 'c':

    MorseDash();

    delay(100);

    MorseDot();

    delay(100);

    MorseDash();

    delay(100);

    MorseDot();

    delay(100);

    break;

    case 'd':

    MorseDash();

    delay(100);

    MorseDot();

    delay(100);

    MorseDot();

    delay(100);

    break;

    case 'e':

    MorseDot();

    delay(100);

    break;

    case 'f':

    MorseDot();

    delay(100);

    MorseDot();

    delay(100);

    MorseDash();

    delay(100);

    MorseDot();

    delay(100);

    break;

    case 'g':

    MorseDash();

    delay(100);

    MorseDash();

    delay(100);

    MorseDot();

    delay(100);

    break;

    case 'h':

    MorseDot();

    delay(100);

    MorseDot();

    delay(100);

    MorseDot();

    delay(100);

    MorseDot();

    delay(100);

    break;

    case 'i':

    MorseDot();

    delay(100);

    MorseDot();

    delay(100);

    break;

    case 'j':

    MorseDot();

    delay(100);

    MorseDash();

    delay(100);

    MorseDash();

    delay(100);

    MorseDash();

    delay(100);

    break;

    case 'k':

    MorseDash();

    delay(100);

    MorseDot();

    delay(100);

    MorseDash();

    delay(100);

    break;

    case 'l':

    MorseDot();

    delay(100);

    MorseDash();

    delay(100);

    MorseDot();

    delay(100);

    MorseDot();

    delay(100);

    break;

    case 'm':

    MorseDash();

    delay(100);

    MorseDash();

    delay(100);

    break;

    case 'n':

    MorseDash();

    delay(100);

    MorseDot();

    delay(100);

    break;

    case 'o':

    MorseDash();

    delay(100);

    MorseDash();

    delay(100);

    MorseDash();

    delay(500);

    break;

    case 'p':

    MorseDot();

    delay(100);

    MorseDash();

    delay(100);

    MorseDash();

    delay(100);

    MorseDot();

    delay(100);

    break;

    case 'q':

    MorseDash();

    delay(100);

    MorseDash();

    delay(100);

    MorseDot();

    delay(100);

    MorseDash();

    delay(100);

    break;

    case 'r':

    MorseDot();

    delay(100);

    MorseDash();

    delay(100);

    MorseDot();

    delay(100);

    break;

    case 's':

    MorseDot();

    delay(100);

    MorseDot();

    delay(100);

    MorseDot();

    delay(100);

    break;

    case 't':

    MorseDash();

    delay(500);

    break;

    case 'u':

    MorseDot();

    delay(100);

    MorseDot();

    delay(100);

    MorseDash();

    delay(500);

    break;

    case 'v':

    MorseDot();

    delay(100);

    MorseDot();

    delay(100);

    MorseDot();

    delay(100);

    MorseDash();

    delay(100);

    break;

    case 'w':

    MorseDot();

    delay(100);

    MorseDash();

    delay(100);

    MorseDash();

    delay(100);

    break;

    case 'x':

    MorseDash();

    delay(100);

    MorseDot();

    delay(100);

    MorseDot();

    delay(100);

    MorseDash();

    delay(100);

    break;

    case 'y':

    MorseDash();

    delay(100);

    MorseDot();

    delay(100);

    MorseDash();

    delay(100);

    MorseDash();

    delay(100);

    break;

    case 'z':

    MorseDash();

    delay(100);

    MorseDash();

    delay(100);

    MorseDot();

    delay(100);

    MorseDot();

    delay(100);

    break;

    default:

       break;

  }
}

	
				
			
				
					int buzzer=8;// initialize digital IO pin that controls the buzzer
void setup() 
{ 
  pinMode(buzzer,OUTPUT);// set pin mode as “output”
} 
void loop() 
{
digitalWrite(buzzer, HIGH); // produce sound
}
				
			
				
					//NR2- PWM DC Motor

int pwmPin = 8; // assigns pin 12 to variable pwm
int pot = A0; // assigns analog input A0 to variable pot
int val=0;

int c1 = 0;   // declares variable c1

int c2 = 0;   // declares variable c2




void setup()  // setup loop

{

  pinMode(pwmPin, OUTPUT); 

  pinMode(pot, INPUT);  
  Serial.begin(9600);

}


void loop()

{
 c2= analogRead(pot); 

  c1= 1024-c2;         // subtracts c2 from 1000 ans saves the result in c1

  digitalWrite(pwmPin, HIGH); 

  delayMicroseconds(c1);   

  digitalWrite(pwmPin, LOW);  

  delayMicroseconds(c2);  
}