Thursday, August 5, 2021

C Program for Bus stop using switch case

 #include <stdio.h>

#include <string.h>

int main()

{

    char stop;

    printf("\tTNSTC\n");

    printf("Mannargudi to Palani\nPoint to Point\n");

    printf("Bus Route\n1.Mannargudi\n2.Thanjavur\n3.Trichy\n4.Manapaarai\n5.Ottanchathiram\n6.Dindugal\n7.Palani\n");

    printf("Enter your stop:");

    scanf("%c",&stop);

        switch(stop)

        {

            case '1':

            printf("This Stoping is Thanjavur\nBus Door Opens\n");

            break;

            

            case '2':

            printf("This Stoping is Trichy\nBus Door Opens\n");

            break;

            

            case '3':

            printf("This Stoping is Manapaarai\nBus Door Opens\n");

            break;

            

            case '4':

            printf("This Stoping is Ottanchathiram\nBus Door Opens\n");

            break;

            

            case '5':

            printf("This Stoping is Dindugal\nBus Door Opens\n");

            break;

            

            case '6':

            printf("This Stoping is Palani\nBus Door Opens\n");

            break;

            

            default:

            printf("No Stops");

        }

    

    return 0;

}

We are using online GDB Complier to compile this program here is the program link

https://onlinegdb.com/1ysKtzQkh


Wednesday, August 4, 2021

IoT Energia source code for IR Sensor obstacle detection and Temperature Sensing using CC3200





IoT Energia source code for IR Sensor obstacle detection using CC3200

#ifndef __CC3200R1M1RGC__

// Do not include SPI for CC3200 LaunchPad

#include <SPI.h>

#endif

#include <WiFi.h>

#include <Wire.h>

#include "Adafruit_TMP006.h"

#include <stdlib.h>

// ThingSpeak Settings

char thingSpeakAddress[] = "api.thingspeak.com";

String writeAPIKey = "HK8345X0Q2JX0L36";

const int updateThingSpeakInterval = 16 * 1000; // Time interval in milliseconds to update ThingSpeak (number of seconds * 1000 = interval)

//buffer for float to string

char buffer[25];

// your network name also called SSID

char ssid[] = "R2C";

// your network password

char password[] = "r2cudt@2021";

// initialize the library instance:

WiFiClient client;

unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds

boolean lastConnected = false; // state of the connection last time through the main loop

const unsigned long postingInterval = 10*1000; //delay between updates to xively.com

int failedCounter = 0;

Adafruit_TMP006 tmp006(0x41); // start with a diferent i2c address!

void setup() {

//Initialize serial and wait for port to open:

Serial.begin(115200);

pinMode(2,INPUT);

pinMode(10,OUTPUT);

pinMode(29,OUTPUT);

// attempt to connect to Wifi network:

Serial.print("Attempting to connect to Network named: ");

// print the network name (SSID);

Serial.println(ssid);

// Connect to WPA/WPA2 network. Change this line if using open or WEP network:

WiFi.begin(ssid, password);

while ( WiFi.status() != WL_CONNECTED) {

// print dots while we wait to connect

Serial.print(".");

delay(300);

}

if (! tmp006.begin()) {

Serial.println("No sensor found");

while (1);

}

Serial.println("\nYou're connected to the network");

Serial.println("Waiting for an ip address");

while (WiFi.localIP() == INADDR_NONE) {

// print dots while we wait for an ip addresss

Serial.print(".");

delay(300);

}

Serial.println("\nIP Address obtained");

printWifiStatus();

}

void loop() {

// if there's incoming data from the net connection.

// send it out the serial port. This is for debugging

// purposes only:

while (client.available()) {

char c = client.read();

Serial.print(c);

}

// if there's no net connection, but there was one last time

// through the loop, then stop the client:

if (!client.connected() && lastConnected) {

Serial.println();

Serial.println("disconnecting.");

client.stop();

}

// if you're not connected, and ten seconds have passed since

// your last connection, then connect again and send data:

if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) {

// read the temp sensor:

// read the temp sensor:


float t =tmp006.readObjTempC();

int ir = analogRead(2);

//no one near the door

if (ir<1000)

{


 digitalWrite(10,LOW); //buzzer ff

//turning on ac and heater based on the temperature

if(t<23)

{

digitalWrite(9,LOW);// Ac off

digitalWrite(29,HIGH);// heater on

}

else

{

digitalWrite(9,HIGH);// Ac ON

digitalWrite(29,LOW);// heater OFF

}

}

//checking for person near door

else

{

//some one near the door

digitalWrite(10,HIGH); //buzzer on

//turning on ac and heater based on the temperature

if(t<23)

{

digitalWrite(9,LOW);// fan off

digitalWrite(29,HIGH);// heater on

}

else

{

digitalWrite(9,HIGH);// Ac ON

digitalWrite(29,LOW);// heater OFF

}

}



Serial.print("IR value ");


String sir = dtostrf(ir,3,3,buffer);


Serial.print(sir);

Serial.print("Temp ");


String st= dtostrf(t,3,3,buffer);


Serial.print(st);


//send to server

updateThingSpeak("field1=" + st+"&field2=" + sir);

}

// store the state of the connection for next time through

// the loop:

lastConnected = client.connected();

}

void updateThingSpeak(String tsData)

{

if (client.connect(thingSpeakAddress, 80))

{

client.print("POST /update HTTP/1.1\n");

client.print("Host: api.thingspeak.com\n");

client.print("Connection: close\n");

client.print("X-THINGSPEAKAPIKEY: "+writeAPIKey+"\n");

client.print("Content-Type: application/x-www-form-urlencoded\n");

client.print("Content-Length: ");

client.print(tsData.length());

Serial.println(">>TSDATALength=" + tsData.length());

client.print("\n\n");

client.print(tsData);

Serial.println(">>TSDATA=" + tsData);

lastConnectionTime = millis();

if (client.connected())

{

Serial.println("Connecting to ThingSpeak...");

Serial.println();

failedCounter = 0;

}

else

{

failedCounter++;

Serial.println("Connection to ThingSpeak failed ("+String(failedCounter, DEC)+")");

Serial.println();

}

}

else

{

  failedCounter++;

Serial.println("Connection to ThingSpeak Failed ("+String(failedCounter, DEC)+")");

Serial.println();

lastConnectionTime = millis();

}

}

// This method calculates the number of digits in the

// sensor reading. Since each digit of the ASCII decimal

// representation is a byte, the number of digits equals

// the number of bytes:

int getLength(int someValue) {

// there's at least one byte:

int digits = 1;

// continually divide the value by ten,

// adding one to the digit count for each

// time you divide, until you're at 0:

int dividend = someValue / 10;

while (dividend > 0) {

dividend = dividend / 10;

digits++;

}

// return the number of digits:

return digits;

}

void printWifiStatus() {

// print the SSID of the network you're attached to:

Serial.print("SSID: ");

Serial.println(WiFi.SSID());

// print your WiFi shield's IP address:

IPAddress ip = WiFi.localIP();

Serial.print("IP Address: ");

Serial.println(ip);

// print the received signal strength:

long rssi = WiFi.RSSI();

Serial.print("signal strength (RSSI):");

Serial.print(rssi);

Serial.println(" dBm");

}

Tuesday, August 3, 2021

Energia code for IoT Temperature Monitoring using cc3200

 



Required:

Energia – the IDE

Adafruit_TMP006-master – a temp sensor lib

WiFiThingspeakClient – the code

Code:

#ifndef __CC3200R1M1RGC__

// Do not include SPI for CC3200 LaunchPad

#include <SPI.h>

#endif

#include <WiFi.h>

#include <Wire.h>

#include "Adafruit_TMP006.h"

#include <stdlib.h>


// ThingSpeak Settings

char thingSpeakAddress[] = "api.thingspeak.com";

String writeAPIKey = "S5CEPJUL7KFTHSES";

const int updateThingSpeakInterval = 16 * 1000; // Time interval in milliseconds to update ThingSpeak (number of seconds * 1000 = interval)


//buffer for float to string

char buffer[25];

// your network name also called SSID

char ssid[] = "R2C";

// your network password

char password[] = "r2cudt@2021";


// initialize the library instance:

WiFiClient client;


unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds

boolean lastConnected = false; // state of the connection last time through the main loop

const unsigned long postingInterval = 10*1000; //delay between updates to xively.com

int failedCounter = 0;


Adafruit_TMP006 tmp006(0x41); // start with a diferent i2c address!

void setup() {

//Initialize serial and wait for port to open:

Serial.begin(115200);


// attempt to connect to Wifi network:

Serial.print("Attempting to connect to Network named: ");

// print the network name (SSID);

Serial.println(ssid);

// Connect to WPA/WPA2 network. Change this line if using open or WEP network:

WiFi.begin(ssid, password);

while ( WiFi.status() != WL_CONNECTED) {

// print dots while we wait to connect

Serial.print(".");

delay(300);

}


if (! tmp006.begin()) {

Serial.println("No sensor found");

while (1);

}


Serial.println("\nYou're connected to the network");

Serial.println("Waiting for an ip address");


while (WiFi.localIP() == INADDR_NONE) {

// print dots while we wait for an ip addresss

Serial.print(".");

delay(300);

}


Serial.println("\nIP Address obtained");

printWifiStatus();

}

void loop() {

// if there's incoming data from the net connection.

// send it out the serial port. This is for debugging

// purposes only:

while (client.available()) {

char c = client.read();

Serial.print(c);

}


// if there's no net connection, but there was one last time

// through the loop, then stop the client:

if (!client.connected() && lastConnected) {

Serial.println();

Serial.println("disconnecting.");

client.stop();

}


// if you're not connected, and ten seconds have passed since

// your last connection, then connect again and send data:

if (!client.connected() && (millis() - lastConnectionTime > postingInterval)) {

// read the temp sensor:

float objt = tmp006.readObjTempC();

Serial.print("Object Temperature: ");

String sobjt = dtostrf(objt,3,3,buffer);

Serial.print(sobjt);

Serial.println("*C");

float diet = tmp006.readDieTempC();

Serial.print("Die Temperature: "); Serial.print(diet); Serial.println("*C");

//send to server

updateThingSpeak("field1=" + sobjt);

}

// store the state of the connection for next time through

// the loop:

lastConnected = client.connected();

}

void updateThingSpeak(String tsData)

{

if (client.connect(thingSpeakAddress, 80))

{

client.print("POST /update HTTP/1.1\n");

client.print("Host: api.thingspeak.com\n");

client.print("Connection: close\n");

client.print("X-THINGSPEAKAPIKEY: "+writeAPIKey+"\n");

client.print("Content-Type: application/x-www-form-urlencoded\n");

client.print("Content-Length: ");

client.print(tsData.length());

Serial.println(">>TSDATALength=" + tsData.length());

client.print("\n\n");


client.print(tsData);

Serial.println(">>TSDATA=" + tsData);


lastConnectionTime = millis();


if (client.connected())

{

Serial.println("Connecting to ThingSpeak...");

Serial.println();


failedCounter = 0;

}

else

{

failedCounter++;


Serial.println("Connection to ThingSpeak failed ("+String(failedCounter, DEC)+")");

Serial.println();

}


}

else

{

failedCounter++;


Serial.println("Connection to ThingSpeak Failed ("+String(failedCounter, DEC)+")");

Serial.println();


lastConnectionTime = millis();

}

}

// This method calculates the number of digits in the

// sensor reading. Since each digit of the ASCII decimal

// representation is a byte, the number of digits equals

// the number of bytes:


int getLength(int someValue) {

// there's at least one byte:

int digits = 1;

// continually divide the value by ten,

// adding one to the digit count for each

// time you divide, until you're at 0:

int dividend = someValue / 10;

while (dividend > 0) {

dividend = dividend / 10;

digits++;

}

// return the number of digits:

return digits;

}


void printWifiStatus() {

// print the SSID of the network you're attached to:

Serial.print("SSID: ");

Serial.println(WiFi.SSID());


// print your WiFi shield's IP address:

IPAddress ip = WiFi.localIP();

Serial.print("IP Address: ");

Serial.println(ip);


// print the received signal strength:

long rssi = WiFi.RSSI();

Serial.print("signal strength (RSSI):");

Serial.print(rssi);

Serial.println(" dBm");

}


R2C Thingspeak

Sunday, August 1, 2021

Core-Python for tax invoices.

 print("\t....personal tax invoices....")

while True:

    print("\n\t1.LIC Insurance\n\t2.Electric bill\n\t3.Bank Loan")

    a1="-*-*-LIC Insurance-*-*-"

    b1="-*-*-Electric bill-*-*-"

    c1="-*-*-Bank Loan-*-*-"    

    a=int(input("\n\tchoose:"))

    if a==1:

        print("\n\t", a1)

        print("\n\tloan interest")

        month=input("\n\tmonth:")

        if month=="present":

            amount=int(input("\n\tIntereset Amount:"))

            print("\n\tTotal amount:",amount)

            print("\n\tAmount payed")

        else:

            amount=int(input("\n\tIntereset Amount:"))  

            penalty=(amount * (2/100))

            total=penalty+amount 

            print("\n\tpenalty:",penalty)

            print("\n\tTotal amount:",total)

            print("\n\tAmount payed")

           

    elif a==2:

        print("\n\t", b1)

        print("\n\tElectric bill")

        month=input("\n\tmonth:")

        print("\n\tElectric bill for",month,"month")

        if month=="present":

            amount=int(input("\n\tE-Charge:"))

            print("\n\tTotal amount:",amount)

            print("\n\tAmount payed")

        else:

            amount=int(input("\n\tE-Charge :"))

            penalty=(amount * (50/100))

            total=penalty+amount

            print("\n\tpenalty:",penalty)

            print("\n\tTotal amount:",total)

            print("\n\tAmount payed")            

    else:

        print("\n\t", c1)

        print("\n\tloan interest")

        month=input("\n\tmonth:")

        print("\n\tloan interest for",month,"month")

        if month=="present":

            amount=int(input("\n\tIntereset Amount:"))

            print("\n\tTotal amount:",amount)

            print("\n\tAmount payed")            

        else:

            amount=int(input("\n\tIntereset Amount :"))

            penalty=(amount * (20/100))

            total=penalty+amount

            print("\n\tpenalty:",penalty)

            print("\n\tTotal amount:",total)

            print("\n\tAmount payed")


Output:




Core-python for probability of getting tail and head.

 print("\t possiblity of getting heads or tails")

while True:

    e=str(input("Enter the head or tail: "))

    head=3

    tail=3

    head_only=1

    tail_only=1

    a=('ht, th, tt')

    b=('hh, th, ht')

    c=('tt')

    d=('hh')

    x=e

    if x=='head':

        print('The probability for getting head:',head)

        print(b)

        break

    elif x=='tail':

        print('The probability for getting tail:',tail)

        print(a)

        break

    elif x=="tail_only":

        print('The probability for getting tail only :',tail_only)

        print(c)

        break

    elif x=="head_only":

        print('The probability for getting head only:',head_only)

        print(d)

        break


Output:




Core-Python for simple fruits Billing.

 print("\t*****Raju super market*****")
def product_of_value(a,b):
    c=a*b
    return c
  
Q=1  
d=0  
while Q<=5:
    name = str(input("\n\tEnter the fruits name:"))
    a = float(input("\tEnter the Quatities:"))
    a1 = [120, 35, 210, 40, 140, 3]
    if name==('apple'):
        b=a1[0]
        c=product_of_value(a,b)
        print("\tAmount:",c)
        Q=Q+1
        
    elif name==('orange'):
        b=a1[-2]
        c=product_of_value(a,b)
        print("\tAmount:",c)
        Q=Q+1

    elif name==('mango'):
        b=a1[-3]
        c=product_of_value(a,b)
        print("\tAmount:",c)
        Q=Q+1

    elif name==('banana'):
        b=a1[-1]
        c=product_of_value(a,b)
        print("\tAmount:",c)
        Q=Q+1

    elif name==('pomegranate'):
        b=a1[2]
        c=product_of_value(a,b)
        print("\tAmount:",c)
        
    elif name==('papaya'):
        b=a1[1]
        c=product_of_value(a,b)
        print("\tAmount:",c)
        Q=Q+1
   
    d+=c
    print("\ttotal:",d)    

Output:









Core-Python program for simple Arithmetic operator.

 print('Enter  the values')

a=7

b=5

print('first value:',a)

print('second value:',b)

c=a+b

d=a-b

e=a*b

f=a/b

g=a%b

print("The sum of the values {0}and{1} is: {2}".format(a,b,c))

print("The Difference of the values {0}and{1} is: {2}".format(a,b,d))

print("The Multiple of the values {0}and{1} is: {2}".format(a,b,e))

print("The Division of the given values {0}and{1} is: {2}".format(a,b,f))

print("The Remainder of the given values {0}and{1} is: {2}".format(a,b,g))



✅ *AI Model Evaluation Interview Questions & Answers* 🧠📊

✅ *AI Model Evaluation Interview Questions & Answers* 🧠📊 *1️⃣ Q: What is a confusion matrix, and how do you interpret it?*   *A:* A co...