Arduino code samples


  • AnalogRead Average reading

  • LCD 16x2 basic connection

  • 74HC595 shift with Arduino


    • AnalogRead Average reading

      float readVoltage()
      {
        float total=0;
        for(int n=0;n<100;n++)
         {
          float temp = (float) analogRead(A0);
          temp = 5.0 * temp/1024;
          total = total + temp;
          delay(1);
         }
       return total/100;
      }
      

      Top



      LCD 16x2 basic connection

      include <LiquidCrystal.h>
      
      LiquidCrystal lcd(rs, enable, d4, d5, d6, d7);
      
      void setup()
      {
        lcd.begin(16, 2);
        lcd.setCursor(col, row);
        lcd.print("some tex");
      }
      

      Top




      74HC595 shift with Arduino

      //Pin connected to pin 12 (ST_CP) of 74HC595
      int latchPin = 8;
      //Pin connected to pin 11 (SH_CP) of 74HC595
      int clockPin = 12;
      ////Pin connected to pin 14 (DS) of 74HC595
      int dataPin = 11;
      
      void setup() 
      {
        pinMode(latchPin, OUTPUT);
        pinMode(clockPin, OUTPUT);
        pinMode(dataPin, OUTPUT);	
      }
      
      void loop() 
      {
      ShiftData();	
      }
      
      void ShiftData() 
      {
        for (int i = 0; i < 256; i++) {//shift from 0 to 255
          digitalWrite(latchPin, LOW);
          shiftOut(dataPin, clockPin, LSBFIRST, i);
          digitalWrite(latchPin, HIGH);
          delay(100);
        }
      }
      

      Top



0 comments:

Post a Comment

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

Search This Blog

Powered by Blogger.

Contributors

Text Widget