Go Down

Topic: connect pushbutton and led using I2C (Read 2 times) previous topic - next topic


Did you mean ground at master and slave must be connected together?

Yes, and put a 4K7 resistor from A4 to +5V and another one from A5 to +5V

did you mean I2C always send high only?

Yes, the code still does, you need to send LOW when the switch CHANGES to a low state.

/ i dont understand in this part, it is boolean or math expression?

Boolean IS maths.

//what != it use be?

It means " not equal to "

if (digitalRead(BUTTON) != last_state){

Means if what you read is not equalt to what it was last time. Now that code is wrong, you need to set last_state to the current state at the end of the loop. That loop function should look like:-

Code: [Select]
boolean last_state = HIGH;                                         
void loop() {   
int button_state = digitalRead(BUTTON)                                                     
  if (button_state != last_state){                     
    last_state = button_state;
    Serial.println("Beginning transmission");
    Serial.println("Sent Data");
    Serial.println("Ended transmission");


thanks to you guy for explanation.

i just follow this picture/tutorial, so the picture is not correct? i must connected A4 and A5 with resistor and supply is it?

hardware i follow before http://www.gammon.com.au/forum/?id=10896


Look you are asking for advice and I am giving it.
Yes that photo is insufficient. Why do you think I told you about pull up resistors.
If you don't want to believe me then don't bother asking.
Read the details here if you can understand it.


yes, i believe with you, i don't mean to not trust you,

i appreciate your help, thanks for give and help me to study i2C.

i will follow your guide..

thanks for the help, and sorry for my poor english


for this recievEvent function it is compulsary to add void receiveEvent(int howMany)

Yes it is known as a call back function, it is triggered when the I2C circuits detect something arriving.

and to write the while (Wire.available() > 0)

The while is a command that causes a loop to happen, it is used here to ensure that you gather all the bytes that are currently waiting in the I2C buffer. So it is not compulsory but you need to replace it with something that will do the same job.

Code: [Select]
boolean b = Wire.receive();    // this also
This creates a variable of type boolean to put the received byte from the I2C interface into. It needs to go somewhere and in this example you only need a logic variable (boolean) that is high or low.

Go Up