# Issue when synchronizing several devices with second()

**URL:** https://discourse.processing.org/t/issue-when-synchronizing-several-devices-with-second/39470
**Category:** Project Guidance
**Created:** [October 28, 2022, 2:09pm UTC](https://discourse.processing.org/t/issue-when-synchronizing-several-devices-with-second/39470 "2022-10-28T14:09:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![patricio1979](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/patricio1979/32/13609_2.png) [@patricio1979](https://discourse.processing.org/u/patricio1979)
#### Post date: [October 28, 2022, 2:09pm UTC](https://discourse.processing.org/t/issue-when-synchronizing-several-devices-with-second/39470/1 "2022-10-28T14:09:46Z")

</div>

I’m doing a music synchronization code but in my imagination all devices works on the same clock. Is this not true?  
When I execute this code on three devices (mi laptop, cellphone, and Android Tablet) the all go in different phases.  
Is this how devices work with the clock?  
Do yo know any better solution?

```auto
let minuto,
    minutoEqual = true,
    primera = false;

function setup() {
  createCanvas(windowWidth, windowHeight);
  minuto = minute();
  textSize(50);
  textAlign(CENTER);
}

function draw() {
  background(255);
  
  //PREVIA
  if (minutoEqual){
    let segundo = 60-second();
    text(segundo,windowWidth/2,windowHeight/2)
    minutoChange = minute();
    if(minuto != minutoChange){
      minutoEqual = false;
      print('cambio')
      primera = true;
    }
  }
  
  //PRIMERA
  if(primera){
    text('comenzamos',windowWidth/2,windowHeight/2)
  }
  
  //SEGUNDA a
  
  //SEGUNDA b
  
}

function windowResized() {
  resizeCanvas(windowWidth, windowHeight);
}

```

---

<div class="post-metadata">

### Author: ![scudly](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/scudly/32/5597_2.png) [@scudly](https://discourse.processing.org/u/scudly)
#### Post date: [October 28, 2022, 2:46pm UTC](https://discourse.processing.org/t/issue-when-synchronizing-several-devices-with-second/39470/2 "2022-10-28T14:46:30Z")

</div>

You cell phone probably has the most accurate clock because that’s necessary for it to work with the cell phone networks. Computers usually set their clocks using NTP servers (network time protocol) where they ping some official time-keeping computer on the internet. I don’t think it will be as accurate as the cell phone network, however. Windows or Macs should have some settings interface for making sure that you have that enabled.

Computers, including cell phones and tablets, try to be as fast as they can, but they do not make any guarantees about real-time accuracy. All of them, these days, are running full multi-tasking operating systems which means that the processor is constantly switching between different activities. When that happens, your Processing sketch is paused while the OS goes off to check in with the cell phone tower, or update your desktop clock, or check if you have new email, and so on. This means you can never guarantee that your sketch is running at any given second (or at least any given microsecond). So when the clock ticks over from 59 seconds to 0 seconds, one device is likely to see that happen just a bit before another one does simply because it was distracted by some other program at that moment.

---

<div class="post-metadata">

### Author: ![patricio1979](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/patricio1979/32/13609_2.png) [@patricio1979](https://discourse.processing.org/u/patricio1979)
#### Post date: [October 28, 2022, 4:16pm UTC](https://discourse.processing.org/t/issue-when-synchronizing-several-devices-with-second/39470/3 "2022-10-28T16:16:15Z")

</div>

Oh, those are bad news.I thought I was doing something wrong.  
But the thing is they are seconds apart. See…

> **[Pic4Net: image 1.jpg HRYN8L](https://pic4net.com/pm-HRYN8L.html)**
>
> Pic4Net: image 1.jpg HRYN8L. 1 jpg. Free anonymous image and photo sharing

If the issue is the same, is there a way to access the time from a single website?

---

<div class="post-metadata">

### Author: ![scudly](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/scudly/32/5597_2.png) [@scudly](https://discourse.processing.org/u/scudly)
#### Post date: [October 28, 2022, 6:32pm UTC](https://discourse.processing.org/t/issue-when-synchronizing-several-devices-with-second/39470/4 "2022-10-28T18:32:40Z")

</div>

Poke around in the clock settings on each device and see if you can find the NTP server settings. [time.apple.com](http://time.apple.com) is used for Mac and iOS tablets or possibly your cell phone provider. [time.windows.com](http://time.windows.com) for Windows. I don’t know what android tablets use. Maybe [time.google.com](http://time.google.com)? One would hope that those time servers are all putting out the same values, but who knows?

The next question is how recently has your device synced up with a server. On my android tablet, I can turn off “automatic date and time”, set the time to a wrong value, turn it back on and see it immediately update the time to a “correct” value for some definition of correct. Try doing that on each of your devices and maybe, if you’re lucky, they’ll all sync up to a very similar time value.
