fbpx

www.huvitera.ee/arduino-10A

				
					//NR1 - Swift Register
// URL:  https://docs.arduino.cc/tutorials/communication/guide-to-shift-out/
//**************************************************************//
//  Name    : shiftOutCode, Hello World
//  Author  : Carlyn Maw,Tom Igoe, David A. Mellis
//  Date    : 25 Oct, 2006
//  Modified: 23 Mar 2010
//  Version : 2.0
//  Notes   : Code for using a 74HC595 Shift Register           //
//          : to count from 0 to 255
//****************************************************************
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
void setup() {
//set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
// count from 0 to 255 and display the number
// on the LEDs
for (int numberToDisplay = 0; numberToDisplay < 256; numberToDisplay++) {
// take the latchPin low so
// the LEDs don't change while you're sending in bits:
digitalWrite(latchPin, LOW);
// shift out the bits:
shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
// pause before next value:
delay(500);
}
}
				
			
				
					//NR2-mulla niiskus

int greenLight = 8; //Defining pins
int yellowLight = 9;
int redLight   = 10;
int piezoBuzzer = 11;
int maximumMoistureLevel; //The max moisture level   and current moisture levels will be needed for percentage calculations
int currentMoistureLevel;//Like   so: current/max*100 = Moisture level as a percentage

void moistureDetection(){   //Create a function for all the long code, to keep the loop free
  if(currentMoistureLevel/maximumMoistureLevel   <= 0.1){ //If the moisture is below 10%
    digitalWrite(greenLight, LOW);
     digitalWrite(yellowLight, LOW);
    digitalWrite(redLight, HIGH); //Switch   on red light, and sound the buzzer
    tone(piezoBuzzer, 5000, 500);
    delay(2000);
   }else if (currentMoistureLevel/maximumMoistureLevel <= 0.3 && currentMoistureLevel/maximumMoistureLevel   > 0.1)
  {//if the moisture level is in between 10 and 30%
    digitalWrite(greenLight,   LOW);
    digitalWrite(yellowLight, LOW);
    digitalWrite(redLight, HIGH);   //Switch red light on, but don't sound the buzzer
  }else if (currentMoistureLevel/maximumMoistureLevel   <= 0.6 && currentMoistureLevel/maximumMoistureLevel > 0.3)
  {//if the moisture   level is in between 30 and 60%
    digitalWrite(greenLight, LOW);
    digitalWrite(yellowLight,   HIGH);//Just switch yellow light on
    digitalWrite(redLight, LOW);
  } else   //Otherwise the moisture level is above 60%, and therefore it's good enough
   {
    digitalWrite(greenLight, HIGH);//Switch green light on
    digitalWrite(yellowLight,   LOW);
    digitalWrite(redLight, LOW);
  }
}

void setup() {
   for (int i = 0; i < 4; i++)//Use a for loop, to not have to initiate all the pins   by hand
  {
    pinMode(i, OUTPUT);
  }
  pinMode (A0, INPUT); //A0   is the pin used for the Soil Moisture Sensor
  maximumMoistureLevel = analogRead(A0);
   tone(piezoBuzzer, 5000, 500);
  delay(200);
  tone(piezoBuzzer, 6000, 500);//Make   a sound to show that the program has been initiated.
  delay(600);
  Serial.begin(9600);
}

void   loop() {
  currentMoistureLevel = analogRead(A0); //Keep renewing the readings   for the current moisture level
  moistureDetection();
  delay(100); //Short   delay to not overload the program
  Serial.println(currentMoistureLevel);//Just   so you can see the moisture level as a reading between 0-1023
  
  
}
				
			
				
					char stringToMorseCode[] = "";


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

int note = 1200;      // music note/pitch


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

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


void setup() {  

  Serial.begin(9600);              

}


void loop()

{ 

  char inChar = 0;          

  char inData[100] = "";        // data length of 6 characters

  String variable = "";

  String variable1 = "";

  int index1 = 0;

 

  if ( Serial.available() > 0 ) {                      // Read from Rx from atmega16

    while (Serial.available() > 0 && index1 < 100)     // read till 6th character

    {

      delay(100);

      inChar = Serial.read();      // start reading serilly and save to variable

      inData[index1] = inChar;

      index1++;

      inData[index1] = '\0';         // Add a null at the end

    }

    variable.toUpperCase();       // convert to uppercase

    for (byte  i = 0 ; i < 100 ; i++) {

      variable.concat(String(inData[i]));    // concat strings

    }

    delay(20);

  }

  String  stringToMorseCode = String(variable);                          


  for (int i = 0; i < sizeof(stringToMorseCode) - 1; i++)

  {

  char tmpChar = stringToMorseCode[i];

  tmpChar = toLowerCase(tmpChar);

  GetChar(tmpChar);

  }

}


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(100);

    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(100);

    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(100);

    break;

    case 'u':

    MorseDot();

    delay(100);

    MorseDot();

    delay(100);

    MorseDash();

    delay(100);

    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;

  }

}