PeterLee
Published © GPL3+

Adjust Brightness of an LED

Adjust brightness of an LED with the PHPoC shield for Arduino.

BeginnerShowcase (no instructions)5 hours6,716
Adjust Brightness of an LED

Things used in this project

Story

Read more

Schematics

Connection Diagram

Code

Code

C/C++
Source Code
#include "SPI.h"
#include "Phpoc.h"

// Arduino web server 
PhpocServer server(80);

char slideName;
int slideValue;

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

  Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
  //Phpoc.begin();

  server.beginWebSocket("remote_slide");

  Serial.print("WebSocket server address : ");
  Serial.println(Phpoc.localIP());  

  analogWrite(9, 100);
}

void loop() {
  // wait for a new client:
  PhpocClient client = server.available();

  if (client) {
    String slideStr = client.readLine();

    if(slideStr)
    {
      slideName = slideStr.charAt(0);
      slideValue = slideStr.substring(1).toInt();

      if(slideName == 'B')
      {
        analogWrite(9, slideValue + 100);
      }

      Serial.print(slideName);
      Serial.print('/');
      Serial.println(slideValue);
    }
  }
}

Credits

PeterLee

PeterLee

2 projects • 11 followers

Comments