How to convert int to char? what I exactly need is if i press digital 2 it have to post 1 again if press digital 2 it have to post 2 if again it have to post 3. please help me
I’m doing arduino ethernet Project, for that i need counter program, but here i can’t able to post a “int” values in twiter, it accept only char,
i’ m using uno and w15 shield
program is
#include <SPI.h>
#include <Ethernet.h>
#include <Twitter.h>
// our event messages
char b1[]=”one”;
char b2[]=”two”;
char b3[]=”three”;
char b4[]=”four”;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // create MAC address for ethernet shield
byte ip[] = { 10,0,0,69}; // choose your own IP for ethernet shield
Twitter twitter(“aaaaaaa”); // replace aaaaaaa with your token
void setup()
{
delay(50);
Ethernet.begin(mac, ip);
Serial.begin(96);
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
}
void tweet(char msg[])
{
Serial.println(“connecting …”);
if (twitter.post(msg))
{
int status = twitter.wait(&Serial);
if (status == 2)
{
Serial.println(“OK.”);
} else
{
Serial.print(“failed : code “);
Serial.println(status);
}
} else
{
Serial.println(“connection failed.”);
}
}
void loop()
{
if (digitalRead(2)==HIGH)
{ tweet(b1); delay(20); }
if (digitalRead(3)==HIGH)
{ tweet(b2); delay(20); }
if (digitalRead(4)==HIGH)
{ tweet(b3); delay(20); }
if (digitalRead(5)==HIGH)
{ tweet(b4); delay(20); }
}
✅ Answers
? Best Answer
int a = ‘a’;
char b = 98;
char[] c = {97,98,99,1};
printf(“int a as an int is %d but as a char it’s %cn”, a, a);
printf(“int b as an int is %d but as a char it’s %cn”, b, b);
printf(“Char c is %sn”, c);
this outputs:
int a as an int is 97 but as a char it’s a
int b as an int is 98 but as a char it’s b
Char c is abcd