Monday, July 15, 2019

Node MCU with WIFI scanning

/*
    This sketch demonstrates how to scan WiFi networks.
    The API is almost the same as with the WiFi Shield library,
    the most obvious difference being the different file you need to include:
*/
#include "ESP8266WiFi.h"

void setup() {
  Serial.begin(115200);

  // Set WiFi to station mode and disconnect from an AP if it was previously connected
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);

  Serial.println("Setup done");
}

void loop() {
  Serial.println("scan start");

  // WiFi.scanNetworks will return the number of networks found
  int n = WiFi.scanNetworks();
  Serial.println("scan done");
  if (n == 0) {
    Serial.println("no networks found");
  } else {
    Serial.print(n);
    Serial.println(" networks found");
    for (int i = 0; i < n; ++i) {
      // Print SSID and RSSI for each network found
      Serial.print(i + 1);
      Serial.print(": ");
      Serial.print(WiFi.SSID(i));
      Serial.print(" (");
      Serial.print(WiFi.RSSI(i));
      Serial.print(")");
      Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : "*");
      delay(10);
    }
  }
  Serial.println("");

  // Wait a bit before scanning again
  delay(5000);
}

output:


Sunday, July 14, 2019

SHT31 Temparature and Humidity sensor with arduino uno


#include <Arduino.h>
#include <Wire.h>
#include "Adafruit_SHT31.h"

Adafruit_SHT31 sht31 = Adafruit_SHT31();

void setup() {
  Serial.begin(9600);

  while (!Serial)
    delay(10);     // will pause Zero, Leonardo, etc until serial console opens

  Serial.println("SHT31 test");
  if (! sht31.begin(0x44)) {   // Set to 0x45 for alternate i2c addr
    Serial.println("Couldn't find SHT31");
    while (1) delay(1);
  }
}


void loop() {
  float t = sht31.readTemperature();
  float h = sht31.readHumidity();

  if (! isnan(t)) {  // check if 'is not a number'
    Serial.print("Temp *C = "); Serial.println(t);
  } else {
    Serial.println("Failed to read temperature");
  }
 
  if (! isnan(h)) {  // check if 'is not a number'
    Serial.print("Hum. % = "); Serial.println(h);
  } else {
    Serial.println("Failed to read humidity");
  }
  Serial.println();
  delay(1000);
}

output::

Tuesday, July 9, 2019

c interview question25

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x=55, y=17;
    printf("%d\n",func(x,y));
    return 0;
}
func (int x, int y)
{
    int q=0;
    if (x<y)
        return 0;
    else
        return func(x-y,y)+1;
}


output::
3

c interview question24

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a=7,b=8;
    printf("%d\n",fune(a,b)) ;
    return 0;
}

fune(int x,int y)
{
    if (x==0)
        return y;
    else
        fune(--x, ++y);
}


output::
15

c interview question 23

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a=2,b=6;
    printf("%d\t",funcl(a,b));
    printf("%d\n",func2(a,b));
    return 0;
}
funcl(int a, int b)
{
    int i,s=0;
    for(i=a;i<=b;i++)
    {s=s+i*i;}
return s;
}
func2(int a, int b)
{
    int s;
    if (a<b)
        s=a*a+func2(a+1,b);
    else
        s=a*a;
}


output::
90      90

c interview question 22

#include <stdio.h>
#include <stdlib.h>

int main()
{
   int n=8;
    printf("%d\n",func(n));
    return 0;
}



func(int n)
{
    if(n==0)
        return 0;
    else
        return(n+func(n-1));
}

output::
36

c interview question 21

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i=0,k=3;
    i+=func(k);
    i+=func(k);
    i+=func(k);
    printf("%d\n",i);
    return 0;
}

func(int k)
{
    static int m=2;
    m=m+k;
    return m;
}

output::
24


explanation:
1st->k=3,m=5,i=5
2nd->k=3,m=8,i=13
3rd->k=3,m=11,i=24

c interview question20

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a=2,b=5;
    a=func(a+b,a-b);
    printf("%d\n",a);
    return 0;
}

func (int x, int y)
{ return x+y, x-y;}

output::
10

c interview questions 19

#include <stdio.h>
#include <stdlib.h>


int a=5;
void func(void );

int main()
{
    func() ;
    printf ("%d\n", a);
    return 0;
}

void func (void)
{
int a=2;
printf ("%d\t", a);
}

output::
2       5

c interview questions18

#include <stdio.h>
#include <stdlib.h>

void func (int a, int b);
int main()
{
    int i=5,j=10;
    func(i/2,j%3) ;

    return 0;
}
void func(int a,int b)
{
    a=a/2;
    b--;
    printf("%d\t",a+b) ;
}

output::
1

c interview question17

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x;
    x=func(2,3,5);
    printf("%d\n",x);
    return 0;
}
func(int a ,int b, int c)
{
    return (a,b,c);
}

output:
5

python class topic video